When two or more people are using my servlet, why does everyone see the data for the person who has logged in latest?

Norman Hanson

[It's probably because you're using instance variables to store data. Instance variables are dangerous in a servlet. Use session attributes instead. -Alex]

If you still want your servlet multithreaded, try creating the data Object in one request (doGet), add the data Object to the users session, then forward to the second servlet where you pick up the object.

// in first servlet doGet...
HttpSession session = request.getSession();
session.setAttribute(dataBeanId, dataBean );
...
RequestDispatcher rd = request.getRequestDispatcher("servlet2uri");
rd.forward(request, response);

// in the second servlet doGet...
HttpSession session = request.getSession();
dataBean = (DataBean)session.getAttribute( dataBeanId );
0 Comments  (click to add your comment)
Comment and Contribute

 

 

 

 

 


(Maximum characters: 1200). You have 1200 characters left.

 

 

About | Sitemap | Contact