• Post Reply Bookmark Topic Watch Topic
  • New Topic

Weird session problem

 
Andres Delrotti
Ranch Hand
Posts: 178
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi everyone,

This is my problem. I have an application where a certain use case follow this sequence

Form Page (jsp page) >> Servlet Controller Action >> Display Page1 (jsp page) >> [next is clicked in page] >> Servlet Action >> Display Page 2 (jsp page)

An intermittent issue happens when this is done by two users. Two users logs in to the application using two different IE6 browser.s

The ff was done

1. User1 fills up the form in the Form Page then submits it.
2. Display Page1 is displayed
3. User2 fills up the form in the Form Page then submits it.
4. Instead of a display page to display the entered data of his form, the display page of data entered by user1 is displayed.

So Basically, user1 entered "xyz" in his form, clicked submit then a page showing "xyz" is shown. For user2, he entered "abc" and when submitted, a page showing "xyz" was shown instead of "abc". This by the way, does not happen every time..which makes it really weird.

The Servlet controller consist of basic request.getparameter codes to retrieve values from form and request.setattribute to display it in the page after. Pages consist of scriplets which have request.getattribute to show the value from the controller. Don't ask why scriptlets was used, its an old app, really old.

Any ideas what could cause this? i would appreciate any help i could get

 
Paul Clapham
Sheriff
Posts: 21892
36
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
There's a good chance that you are storing the entered data in instance (or static) variables in your servlet. And since there's only one instance of the servlet, when two requests try to use the servlet at just about the same time you encounter race conditions. Like the problem you described.

So check out your source code and see if that's it.
 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 65530
108
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Show us the code. Otherwise we can only guess. Please UseCodeTags.
 
Andres Delrotti
Ranch Hand
Posts: 178
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Source codes:

For ServletController class:

String lastName = request.getParameter("lastName")
String totalBillCharges = request.getParameter("totalbillcharges");

request.setAttribute("lastName", lastName);
request.setAttribute("totalBillCharges" , totalBillCharges);

etc..etc..



For display page (scriptlets was used)

<%

String lastName = request.getParameter("lastName")
String totalBillCharges = request.getParameter("totalbillcharges");

etc..etc..

%>

Name: <%=lastName%>
Total Charges: <%=totalCharges%>



Could it be that there was some caching going on in the browser? it is this due to the back end?
 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 65530
108
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Please UseCodeTags.
 
Andres Delrotti
Ranch Hand
Posts: 178
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator



IN JSP:



 
Ahsan Bagwan
Ranch Hand
Posts: 254
1
Java MySQL Database Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I believe in your controller servlet after you have bounded the values to the request scope you are required to obtain it in the JSP using the `getAttribute()` method. See here for the reference - http://docs.oracle.com/javaee/6/api/javax/servlet/ServletRequest.html#getAttribute%28java.lang.String%29

So something like in your display page,




But then again I am not much experienced. Maybe someone else can chime in to improve it or correct it if I am way off.
 
William Brogden
Author and all-around good cowpoke
Rancher
Posts: 13078
6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If you will examine the servlet code that your JSP is compiled to I suspect you will see that those are instance variables you are putting those values in.

Since instance variables are shared between all requests - figure it out for yourself.

Bill
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!