This week's book giveaway is in the OO, Patterns, UML and Refactoring forum. We're giving away four copies of Refactoring for Software Design Smells: Managing Technical Debt and have Girish Suryanarayana, Ganesh Samarthyam & Tushar Sharma on-line! See this thread for details.
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
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.
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.