0

we have a JavaEE Web application that runs on Tomcat5 server (jsp, java and extjs are used on development of this tool).

We observe sometimes, particularly when the application is highly used, that some session variables or interface fields are mixed up in servlets.

This means that : when one user connects, his parameters are kept in the sessions.

After an update or insertion of data in the database ORACLE,the system returns the name of another user who was probably connected at the same time on a different navigator or a different computer. Others times the request.getparameter gets a values from different clients or user interfaces. Thank you to help me fix this problem.

ValerieMT
  • 5
  • 2
  • I bet your servlets have fields and you change their values in `doGet` and/or `doPost` method. – Luiggi Mendoza May 11 '14 at 06:03
  • All the elements got in the servlet are supposed to be originated from the same user session interface. But sometimes the user id or values are mixed up in the http Protocol that brings data to the servlet. – ValerieMT May 12 '14 at 19:43
  • That's not what I mean. Please provide an example of your servlet. – Luiggi Mendoza May 12 '14 at 19:47

2 Answers2

0

The only way for this to happen is if you have a singleton somewhere that keeps track of the session and for some reason this singleton is mixing up the variables between sessions.

You can try this: Instead of differentiating a user only by its credentials (assuming you are not using Federation), return a token, unique amongst all sessions to the user logging in, and make the user send that unique id with every request. This way you will be able to differentiate the request/responses even if the user logs in using many different browsers.

But again, this will only happen when you do something like having a singleton connecting the session, by itself the session would not exchange variables amongst them.

Alexandre Santos
  • 7,654
  • 7
  • 35
  • 60
  • I've tried to keep the session id in the GUI and compare with the other taken from the request when i reach the servlet. But this does not assure me that every parameters are from the same user – ValerieMT May 12 '14 at 19:48
  • Hmmmm. I think you are doing too much and not allowing servlets (and filters) to do their job. Try reading more about how they work. – Alexandre Santos May 12 '14 at 19:52
  • Please would you sent me an address where i can find those details about servlets .java and how to uses them efficiently and between many web client – ValerieMT May 12 '14 at 19:57
  • @user3622677 [How do servlets work? Instantiation, session variables and multithreading](http://stackoverflow.com/q/3106452/1065197) – Luiggi Mendoza May 12 '14 at 20:02
0

I've finally understood how servlet.java works. I works like main process that create a thread for any call thus, all attributes of such class are common to all thread and we are not sure of the result that we get when accessing them.

If we want any client to use those variables in a private context, we must put them in the function "doGet" or "doPost" as local variables.

My problem have them been solved

ValerieMT
  • 5
  • 2