Do Applets use Browser for HTTP Requests?

EngineerBetter_DJ picture EngineerBetter_DJ · Jun 20, 2012 · Viewed 7.1k times · Source

Is there any interaction between applets and their hosting browser when making HTTP requests, or are requests made completely independently of native browser code?

Specifically, do Java applets running in a browser have some implicit way of sharing the browser's session state and cache?

I've read a few posts from non-authoritative sources saying that when an applet makes an HTTP request that it will use the browser's cache, and that it will also have access (somehow) to the browser's cookies.

Tests I've done using URLConnection suggest that this is not the case, and my gut feeling is that it sounds far too convenient to be true. I would assume that nothing in the JVM knows anything about the world outside of that JVM, meaning the only other way this could work would be if the JVM implementation is specific to the browser its implementation of the URL-related methods delegate to native browser code?

If cookie data is not implicitly shared or available, is best practice to pass a session ID in a param tag to the applet? Are there security concerns with this approach? If the applet doesn't use the browser's cache for requests, how does caching requests in an applet work?

Answer

JB Nizet picture JB Nizet · Jun 20, 2012

Applets are executed by the Java Plugin, which is a browser plugin. The applet is indeed part of an HTML page loaded by the browser, can communicate with the browser DOM and with JavaScript code in the page, and uses the browser to send requests to its originating server.

See http://docs.oracle.com/javase/tutorial/deployment/applet/appletExecutionEnv.html and http://docs.oracle.com/javase/tutorial/deployment/applet/server.html for more information.