Meaningless Drivel is fun!*
The moose likes JSP and the fly likes Session variables are getting hosed! Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of OCM Java EE 6 Enterprise Architect Exam Guide this week in the OCMJEA forum!
JavaRanch » Java Forums » Java » JSP
Bookmark "Session variables are getting hosed!" Watch "Session variables are getting hosed!" New topic
Author

Session variables are getting hosed!

K Nally
Greenhorn

Joined: Sep 30, 2003
Posts: 13
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

Joined: Jan 10, 2002
Posts: 61105
    
  66

Are you sure that your problem isn't just stale pages being plucked out of cache?
bear


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
K Nally
Greenhorn

Joined: Sep 30, 2003
Posts: 13
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

Joined: Sep 30, 2003
Posts: 13
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

Joined: Oct 04, 2003
Posts: 541
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


Kim Jong II (North Korea's Dear Leader) said:Nuclear weapons don't kill people, people kill people.
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61105
    
  66

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

Joined: Oct 04, 2003
Posts: 541
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
 
 
subject: Session variables are getting hosed!