How is an HTTPSession created when a request comes from a web server instead of a web browser?

I have a very simple question about how creating an HTTPSession works. I know that you will fire me, considering this issue as a similar issue there. But there are reasons why I ask this question. There he is: -

I know that httpsession is unique to a web browser, and the server creates it when we first do HttpServletRequest.getSession. It will maintain the same session until we close the browser. But I have a slightly different scenario. I have a web application on one instance of tomcat, say T1.On the welcome page of this web application I provided two click-through links that takes me to the same Java servlet (S1) of another web application hosted on another instance tomcat T2 (these two links open two separate pop-ups). Now first I click link1 and check sessionId in S1 and find its value as 1678. Now first I click link2 and check sessionId in S1 and find its value again as 1678.My question is here, why am I getting the same session id for both origintaing requests from link1 and link2? What can I do to get a different session for both of these requests?

What I tried after searching for possible solutions on the network: - . When I clicked link1, in Servlet S1, I copied the session attributes, invalidated and created a new one. Let's say the new session identifier is 8765. Now I click link2 and found the same session in this request too. Therefore, I will not cancel it and create a new one (say, the new session identifier is 4897). Ideally, this should expire the first browser session (generated by clicking link1). To check this, I click anywhere in popup 1, it doesn’t work expired, but I see again the last generated session ID ie 4897. I don’t understand why it attaches the same session ID with both popups?

People Thanks for your patience for taking the time to read this long script?

Edit: -

      Cookie[] cookies = req.getCookies(); 
        if(cookies!=null) 
        for (int i = 0; i < cookies.length; i++) { 
         cookies[i].setMaxAge(0); 
         context.getResponse().getHttpServletResponse().addCookie(cookies[i]);
        } 

    HttpSession myAppSession = req.getSession();//line 1

, link1 1234, 2 . , 1, , MaxAge as0 , . ?

+5
1

, , :

cookie. WebServer cookie. cookie .

, cookie /? . , cookie:

  • : , . , .
  • : . - , .
  • : , cookie . , cookie .

cookie . cookie , . , .

, URI , (.. ) , .

:

  • .
  • .
  • LB node
+8

All Articles