File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Servlets and the fly likes Session ID Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Servlets
Bookmark "Session ID" Watch "Session ID" New topic

Session ID

Raj Kumar
Ranch Hand

Joined: Sep 19, 2005
Posts: 65
Hi all, i have a doubt with regard to sessions below is the case which i had noticed.

I have created a webapplication (it is in beginning stage) with 2 JSP's index1.jsp & index2.jsp and a servlet which acts as a dispatcher to all the JSP's (i.e all the request will bypass only through this servlet)

I had given the following statement in the servlet service method

System.out.println("val "+objReq.getRequestedSessionId());

Now when i open the same page in my webapplication in multiple windows & Tabs using Mozilla it gives the same session id but the same is not the case when i do with IE for each and every window and i open it gives a different session id.

What is the reason behind it???

In some cases IE retunrs session id has null.

When i open my application in IE tab of mozilla all the IE tab returns the same session id which is different from mozilla tab.

I'am confused over it. Pls. explain.

I had not given any statments like getSession / getSession(true) in my application.

thanks in advance.
Rahul Bhattacharjee
Ranch Hand

Joined: Nov 29, 2005
Posts: 2308
Check if the cookies are disabled in IE.

Rahul Bhattacharjee
LinkedIn - Blog
Raj Kumar
Ranch Hand

Joined: Sep 19, 2005
Posts: 65
Thanks for the reply Rahul,

I tried to both allow & block and in both the cases IE is either creating new session id each and every time (or) it returns null (very rare and i can't recreate this case)

Two things noted here

1) In IE if i open a new window by using File->Window it gives the same Session id (this case is normal).

2) In Mozilla when i open my application in IE tab even in multiple tabs it gives the same session id for all the IE tabs i started for my application.
Ben Souther

Joined: Dec 11, 2004
Posts: 13410

MSIE behaves differently, in regard to session cookies, depending on how the window was spawned.

If, you open a new window by clicking on Start -> programs -> MSIE, you will get completely new instance of MSIE. It will have it's own space for session cookies and, as you have noted, will start a new session when it accesses your site.

If. on the other hand, you open a new window by typing CTRL+N or by using File-> New... from an existing instance's menus, the new window will share the session cookies with the existing instance. Both will take part in the same session.

Java API J2EE API Servlet Spec JSP Spec How to ask a question... Simple Servlet Examples jsonf
I agree. Here's the link:
subject: Session ID
It's not a secret anymore!