Win a copy of The Java Performance Companion this week in the Performance forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

session variable problem, please help

 
ban yan
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 64972
86
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Kalai Selvan
Ranch Hand
Posts: 79
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 49
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Have it pop-up until you verified the value of the session variable.
 
Vijayendra V Rao
Ranch Hand
Posts: 195
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic