This week's book giveaway is in the Java 8 forum.
We're giving away four copies of Java 8 in Action and have Raoul-Gabriel Urma, Mario Fusco, and Alan Mycroft on-line!
See this thread for details.
The moose likes Servlets and the fly likes session variable problem, please help Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Java 8 in Action this week in the Java 8 forum!
JavaRanch » Java Forums » Java » Servlets
Bookmark "session variable problem, please help" Watch "session variable problem, please help" New topic
Author

session variable problem, please help

ban yan
Greenhorn

Joined: Jul 22, 2004
Posts: 1
I have a search page with a "search button", after hit that button I call a servlet. The servlet does some database operation and then puts the search result into a session variable. At the same time to hit the search button, another "search result" page pop-up. The result page should read the session variable, and then display the result.

My problem is: sometimes, the server runs so fast, when I try to read the session variable in result page, it is still null or I just get the old session value.

This problem really drives me crazy. Could some one give a good solution to solve this.

Thanks a lot!!!
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 60072
    
  65

That's called a 'race condition' and it's been created at your own choosing. Change things so that the results page doesn't display until after the results have been obtained.


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
Kalai Selvan
Ranch Hand

Joined: Jul 07, 2004
Posts: 79
Hi,
What you can probably do is, After processing the data in the servlet, initiate (i.e. popup) the result.jsp from the servlet.

One way of doing this is... forward the request to intermediate.jsp and in that jsp file say window.open with the necessary parameters. In this way your result.jsp will be called only after the servlet processing is complete.

bye,
Kalai S.
john von
Ranch Hand

Joined: Apr 13, 2004
Posts: 49
Have it pop-up until you verified the value of the session variable.
Vijayendra V Rao
Ranch Hand

Joined: Jul 04, 2004
Posts: 195
Originally posted by Bear Bibeault:
That's called a 'race condition' and it's been created at your own choosing. Change things so that the results page doesn't display until after the results have been obtained.


I think this would be the best way to do.

You can probably not make a call to that Results pop-up page until the session variable has been populated with the latest results.


Vijayendra <br /> <br />"The harder you train in peace, the lesser you bleed in war"
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: session variable problem, please help
 
Similar Threads
how to get refrance of a current executing thread of a servlet
Page expired message
Bean constructor
How to use ConnectionPool in jsp
Does a servlet continue processing after I hit Stop?