File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes JSP and the fly likes Session variable too slow in getting set? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » JSP
Bookmark "Session variable too slow in getting set?" Watch "Session variable too slow in getting set?" New topic

Session variable too slow in getting set?

Gail Mikels
Ranch Hand

Joined: May 07, 2001
Posts: 634
I have two jsp's in a frameset (top.jsp & bottom.jsp). User makes a selection from select box in bottom.jsp. The select's onchange method sets the new value in a hidden form element of bottom.jsp, then submits the form. When the form reloads, it grabs the new value using request.getParameter(), then sets a session variable using session.setAttribute(). Next, it reloads top.jsp, and top tries to grab that session variable to display that new value in the top.jsp.
This only works "sometimes". Other times, the top reloads too soon, grabbing the session variable before it gets set, so it displays the OLD value.
Is there any way to find out when a form is "done" submitting, so I can wait on reloading top.jsp 'til the session variable is set? Or is there another way to ensure that one process is done before the next starts? Any ideas???
Many Thanks,

Gail Mikels
Anthony Watson
Ranch Hand

Joined: Sep 25, 2003
Posts: 327
The HTML body element has an onload event. This event fires when the entire page has been loaded. Thus, you should write a JavaScript function that reloads the top page that is called when the bottom page's body onload event is fired. That will ensure that the bottom page has finished processing the session variable before your top page tries to access the new value.

Anthony W.<br />MCP, SCJP 1.4, SCJD, SCWCD 1.3, SCWCD 1.4, SCBCD
I agree. Here's the link:
subject: Session variable too slow in getting set?
It's not a secret anymore!