wood burning stoves 2.0*
The moose likes JSP and the fly likes Session variable incorrect value Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Java » JSP
Bookmark "Session variable incorrect value" Watch "Session variable incorrect value" New topic
Author

Session variable incorrect value

Apreet Singh
Greenhorn

Joined: Oct 10, 2012
Posts: 6
Hi

I have a drop down <select> in jsp having city names. Current city value comes from session attribute.
On change Java script function is called which through AJAX calls second jsp which updates the session
attribute value with new city.

From it's response I can see correct city value is being passed and attribute is being reset correctly.

But after the first jsp reloads, it is not using correct attribute value.

When I change from Delhi to Gurgaon, it stays Delhi
If I change to Noida, it changes
But then if I try to change to anything else it just stays at Noida

I have spent few hours trying to diagnose but I am not able to get the underlying issue

Kindly suggest what may be wrong

Code

First jsp


Second jsp






Stefan Evans
Bartender

Joined: Jul 06, 2005
Posts: 1016
Your browser is caching the responses to your ajax calls. You can see this if you add logging into your second JSP.
The first couple work, but after that, it just returns a cached response without actually invoking the server.

Suggestion:
Change

to

The rules of caching are different for get and post requests.
GET is assumed to be cachable.
POST for the most part is not.
If you are actually changing something (which you are) you should POST, rather than GET.

If that doesn't work then take a look at the JSP FAQ: No-Cache Headers
Apreet Singh
Greenhorn

Joined: Oct 10, 2012
Posts: 6
Thanks a lot Stefan Evans.

By changing request type to POST , it's working fine.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Session variable incorrect value
 
Similar Threads
Regading getElementById
struts-2 (set values to action class)
Problem with items auto change when using IE
iterate doubt
how the response from ajax in jsp page get refresh when two dropdown fetch from database dependent