简体   繁体   中英

Is there a way to read the browser's cookie from a java applet?

I have a java applet that needs to do http requests to the server. A quick experiment showed that the session id cookies from the browser is not sent along, so i'll have to set it manually. Currently, I see 2 possible solutions:

  • somehow get hold of the cookie data from within the applet
  • pass the cookie information into the applet's contructor via javascript

I'd prefer the first solution, but i wasn't able to find a working solution for that. all information i found (mostly netscape.javascript.JSObject) were outdated (my 1.5 VM does not have this class)

Any great ideas or resources i have not yet found?

Are you sure your JVM doesn't contain this class? You should look in $JAVA_HOME/lib/plugin.jar . I found it in my 1.5.0_14 installation.

If you are generating the page dynamically, you don't necessarily need to use JavaScript to communicate the session ID. As long as you know it server-side, you can place it into an applet parameter tag in the generated HTML which contains the <applet> tag.

如今,所有浏览器都支持httponly cookie。如果在相应的响应标头中有意识地在服务器中将cookie设置为“ httponly”,则小应用程序可能无法访问它。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM