Store variable in (servlet) session from JavaScript

K

Kai Grossjohann

I have a Web application (JSP/servlet mix) which uses multiple frames.
I would like to remember frame sizes across reloads done by the user
and also across links. To this end, I thought it is best to store the
frame sizes in the HTTP session.

I already have code which runs off of <body onUnload="..."> that
figures out the frame size. In order to store the frame size in the
HTTP session, I thought it was easiest to invoke a JSP which takes the
size as a request parameter and then stores it in the session.

So, I would like to write JavaScript code which invokes a certain URL,
say

/my_webapp/remember_framesize.jsp?width=185

from the onUnload handler. I found that I could do this by calling
window.open with that URL:

window.open("/my_webapp/remember_framesize.jsp?width="
+ frame_width, "dependent=yes");

And remember_framesize.jsp stores the request parameter in the session
and then calls window.close().

This is fine as far as it goes, but as you can imagine, having this
window pop up for a fraction of a second and then disappear is not so
nice.

Another problem is that the unloading of the page proceeds normally,
of course, after opening the new window. And then the browser opens
the new page, which is a frameset in my case. And this frameset reads
the frame width from the session. This is a race condition waiting to
happen, of course.


Another alternative is to add the "width" request parameter to all
links going out from the page, and then to teach all target pages
about this parameter, to have them store it in the session. But this
is not really a practical solution, since there are many target pages,
accepting a plethora of other request parameters.


Suggestions?

tia,
Kai
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,754
Messages
2,569,521
Members
44,995
Latest member
PinupduzSap

Latest Threads

Top