Win a copy of Java Mock Exams (software) this week in the Programmer Certification (OCPJP) forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Why I get new session with new request from new browser window on same machine?

Bahadar Khan
Ranch Hand
Posts: 81
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi folks,

I am not sure, what I am doing wrong here but using the following code, when ever I make a request from new browser window from the same machine it starts a new session. But if I repeatedly make requests from one window it doesn't starts new but keeps on adding info in the old session object as per logic. I am using Tomcat 5. Please see the code of servlet and jsp that calls it. And I would appreciate if somebody could tell me why its happening. As per my understanding requests made from same machine, no matter from different browser windows should be pointing to the same Session object.


package sessionpkg;

import javax.servlet.*;
import javax.servlet.http.*;

public class Sessions extends HttpServlet{

String str="";

public void doPost(HttpServletRequest req, HttpServletResponse res) throws, ServletException{

String str1=req.getParameter("snail");

HttpSession session=req.getSession();

String str=(String)session.getAttribute("track");




RequestDispatcher rd=req.getRequestDispatcher("/index.jsp");



Calling JSP CODE ( index.jsp)



<form method=POST action="sessions">

Input a character <input type="text" name="snail">
<input type="SUBMIT">


What are you doing? You are supposed to be reading this tiny ad!
the new thread boost feature brings a LOT of attention to your favorite threads
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!