• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Weird session problem

 
Ranch Hand
Posts: 178
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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

 
Marshal
Posts: 28193
95
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Sheriff
Posts: 67746
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
Sheriff
Posts: 67746
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Please UseCodeTags.
 
Andres Delrotti
Ranch Hand
Posts: 178
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator



IN JSP:



 
Ranch Hand
Posts: 254
1
MySQL Database Java Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Author and all-around good cowpoke
Posts: 13078
6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
reply
    Bookmark Topic Watch Topic
  • New Topic