Win a copy of Clojure in Action this week in the Clojure forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Session leakage problem in Servlet

 
sateesh muggalla
Greenhorn
Posts: 1
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi -

I have a servlet like this:
public class AServlet extends HttpServlet implements java.io.Serializable{

private DBUser User = null;

public void service(HttpServletRequest req, HttpServletResponse res)
throws ServletException, IOException {
String sAction=(req.getParameter("ACTION")!=null)?req.getParameter("ACTION"):"";
try{

User = (DBUser)req.getSession().getAttribute("User");
if (sAction.trim().equals("ADDNOTE")) AddNote(req, res);
}catch (Exception e){
}

public void AddNote(HttpServletRequest req, HttpServletResponse res)
throws SQLException, IOException, ServletException, RuntimeException{
try{
Connection c=DBConn.getDBConn(User.getCompanyDB());
Statement s1=c.createStatement();

System.err.println("Add Notes");

HttpSession session = req.getSession(true);
Project qp=(Project)session.getAttribute("qp");

}catch(){
}
}
}

I have one more session which is there in Addnote(req,res) is qp ...It is giving correct results but when I print the User session details .. It is showing some other user details.

If any two users try to print the User details in AddNote..it is taking the last hitted User details..

Is the problem with DBUser define.....
Here qp session is returning the current values but only User session is overriding .....

Can any one help me out of this error?

Thanks
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 64188
83
IntelliJ IDE Java jQuery Mac Mac OS X
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Please be sure to use code tags when posting code to the forums. Unformatted or unindented code is extremely hard to read and many people that might be able to help you will just move along to posts that are easier to read. Please click this link ⇒ UseCodeTags ⇐ for more information.

Properly indented and formatted code greatly increases the probability that your question will get quicker, better answers.
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 64188
83
IntelliJ IDE Java jQuery Mac Mac OS X
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Looks like you have an instance variable in your servlet. That's a big no-no!

Servlets need to be written in a thread safe manner. Instance variables violate that. The instance is shared across all requests. This has nothing to do with the session.
 
I agree. Here's the link: http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic