• Post Reply Bookmark Topic Watch Topic
  • New Topic

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

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.*;
import java.io.*;
import java.net.*;

public class Sessions extends HttpServlet{

String str="";

public void doPost(HttpServletRequest req, HttpServletResponse res) throws java.io.IOException, 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">


  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!