简体   繁体   中英

How do I send updated cookies to an applet?

I'm creating an applet that needs to receive the user's cookies for authentication. The applet receives all the cookies and browses for the ones it needs. If it doesn't find them, it'll tell the user to authenticate. The applet has no control over the sign-on process.

If the user is already authenticated the first time he opens the applet page, everything is fine.

If he's not, he has to go authenticate at another page, which will set the cookies, and then he has to refresh the applet page. However, the applet is not receiving the updated cookies even after refreshing. It keeps receiving the same ones it received when the user opened the page for the first time.

To send the cookies to the applet, I've tried using:

document.write('<object id="myApplet" classid="java:MyApplet.class"
                        type="application/x-java-applet"
                        archive="myApplet.jar" 
                        height="300"
                        width="500">');
document.write('<param name="cookies" value="' + document.cookie + '" />');
document.write('</object>');

I've also tried the exact same code using innerHTML.

I have the applet printing the value of getParameter("cookies") and it always prints the old values. But, doing a display on document.cookie using alert() or the browser's dev console, it shows the updated cookies.

Turns out one of the cookies contained double-quotes. When the user was already authenticated, that cookie was the last one on the list, so it didn't affect anything. When the user authenticated afterwards, that cookie would be in the middle of the list, closing the tag's quotes and ending the cookie string.

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