Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Cloud/Virtualization forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Session variables are getting hosed!

 
K Nally
Greenhorn
Posts: 13
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have two JSPs and one Class file that is serializable (I call that my "bean") that I use to store values for JSP #1 and JSP#2.
JSP #1 sets a value in my "bean" using a setter method. It does not matter that the value is char, string, or boolean. The user can click on a hyperlink that passes a value back to JSP #1 - and, as a result, I reset the value using the setter method. So far, so good. Now, the user clicks the hyperlink again, so I pass a different value back to JSP #1, and again, I reset the value in the bean. We do this two more times before the user hits the update button and I go to JSP #2 - BUT the value in the bean is the PREVIOUS value - not the one I just set.

In short: this is the sequence:

JSP#1
value = "current"
JSP#1
value = "next"
JSP#1
value = "current"
JSP#1
value= "next"

User presses UPDATE to go to JSP #2. The value JSP#2 picks up is "current". If I hit the "refresh" button before the UPDATE button, the value is CORRECT! This is driving me nuts!

Here is my bean setting in JSP#1 and JSP#2:

<jsp:useBean id="mySession" class="SessionBean" scope="session" />
Thanks for any assistance.
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 64629
86
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Are you sure that your problem isn't just stale pages being plucked out of cache?
bear
 
K Nally
Greenhorn
Posts: 13
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Bear:
It was a caching problem - not at the webserver, but at the browser. I didn't realize that browsers cache .jsp pages also. I guess a good practice may be to add a unique value on the post parameter after the URL?
Thanks.
Karen
 
K Nally
Greenhorn
Posts: 13
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I found the tag that will prevent browser caching:
<META HTTP-EQUIV="Pragma" CONTENT="no-cache">
<META HTTP-EQUIV="Expires" CONTENT="-1">
I added it and this fixed by session variable problem.
 
Tim Baker
Ranch Hand
Posts: 541
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
from a browsers view there is no difference between a .html .jsp .php .cgi or anything else, they are all just HTML files.
once you've finished active development you might want to remove those restrictions on caching, because there are good reasons for browsers to make a cache.
personally i just turn off caching within my own browser to avoid problems
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 64629
86
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
once you've finished active development you might want to remove those restrictions on caching

Not if your pages have active content. You don't want stale content being plucked out of the cache. Also, methinks its a bad idea to deploy with a different configuration than you developed and tested with.
bear
 
Tim Baker
Ranch Hand
Posts: 541
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hence the might
a lot of people are on slow connections (including me!) and so unless it really is second specific data it's wise to allow (at least some) caching
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic