tomcat-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Lionel Farbos <>
Subject Re: session management
Date Mon, 04 Apr 2005 09:31:59 GMT

A cookie is attached to one IP/browser.
So, if the same browser do : 
it recovers the same httpSession as before (if it already exists).
But when you come from another browser, the same httpSession is not recovered.

For your needs, I think you can do something like this :
Use a database in which you store sessionIds when they are created, and you can associate
all the parameters you want to this Id (login,context,...).
When a new browser wants to use to same session as other, it invokes a special servlet with
the required parameters;
Then, this servlet take the desired sessionId in database and returns it as a cookie (So,
here, you case use httpServletResponse.addCookie(...)).
So, your second browser will store the same sessionId as the 1st one and will use the same

Perhaps there are other ways to do this,
but I think this one can work.


On Sat, 2 Apr 2005 12:07:26 -0800 (PST)
Jagadeesha T <> wrote:
> Hi, Thanks the reply,
>  My requirement is little different.
> I want to have many browser instaces (2 or more)to use the same session.
> In my first.jsp, on first hit, i will get the session and store it.
> Again,if the first jsp is hit for the second time. It should use the
> same session. SO, I will not let it allow to create a new one. Instead use the one already
stored for user.
> I have to do like this since the user login is done from a Java Applacition(Swing).
> If the user wants to go to a browser. User has to click on the button (Swing UI) that
will launch the 
> browser. each click on the button should launch a browser.
> I want all those browsers launched for that login to use a shared session object.
> Could you tell How can I do it.
> I tried by setting the cookie at the first.jsp when the second browser launch(Coolke
which had created at the 
> first
> hit).
> addCookie,
>       In one of the middle jsps, there is 
>       response.sendRedirect(response.encodeURL("samepage?somename=somevalue"))
>              Every time,    it is failing here, response.sendRedirect();
>  //When it is reloaded i have observerd that it is not getting the cookie in the headers.
>  I don't understand why the browser not sending the cookie. cookie is not disabled.
> Scenario 2.
> If all browser uses different session objects. then it works fine.
> could you tell me is there any way to get this done?
> Thanks,
> Jagadish
> Lionel Farbos <> wrote:
> On Thu, 31 Mar 2005 11:41:55 -0800 (PST)
> Jagadeesha T wrote:
> > Hi all,
> > I want to set session in httpservletresponse object, Is there 
> > any way to do it.
> > Otherthan response.addCookie(), or 
> > response.encodeURL();
> > Is there any way to set the Jsession In headers, So that it gets that 
> > in the next Jsp by request object, 
> > If I use addCookie of response object, It fails if any where encodeURL 
> > is used. 
> > If i user encodeURL, every JSP needs to updated with that method.
> > Please if anybody knows tell the way that can be done. 
> >
> You don't have to create yourself the cookie.
> You create the HttpSession with HttpServletRequest.getSession() or HttpServletRequest.getSession(boolean)
> Then, the session is created and the cookie JSESSIONID is added to the HttpServletResponse.
> So, the next time you'll invoke a servlet or JSP in the same Context (with the same browser),
> the Cookie JSESSIONID will be attached to your request.
> If you have clustered your Tomcat, the JSESSIONID will have a suffix .,
> so, if you use the mod_jk to load-balance your tomcat clustered servers, 
> your request will be sent to the same tomcat (as the precedent).
> Enjoy
> > Thanks,
> > Jagadeesha T
> > 
> > 
> > 
> > ---------------------------------
> > Do you Yahoo!?
> > Better first dates. More second dates. Yahoo! Personals 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail:
> For additional commands, e-mail:
> ---------------------------------
> Do you Yahoo!?
>  Better first dates. More second dates. Yahoo! Personals 

To unsubscribe, e-mail:
For additional commands, e-mail:

View raw message