• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

reading SESSIONID header.

 
Senthil Kumar
Ranch Hand
Posts: 264
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi,
can't we read the session id header using like this.
req.getHeader("JSESSIONID"))
 
Karthikeyan Varadarajan
Ranch Hand
Posts: 98
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Sendhil,

Why don't you try it yourself by writing a simple servlet/jsp ?
 
Christophe Verré
Sheriff
Pie
Posts: 14691
16
Eclipse IDE Ubuntu VI Editor
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The session id is not part of Http Headers.
 
Vikrant Pandit
Ranch Hand
Posts: 245
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If cookies are being used for session tracking

then you can look for a cookie with the name of JSESSIONID
 
Senthil Kumar
Ranch Hand
Posts: 264
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
karthi,
i've tried it myself and it returns null.But is JSESSIONID not a part of the
request header.
 
Senthil Kumar
Ranch Hand
Posts: 264
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Vivek,
Are you sure a sessionid could be read thru cookies.Bcoz when i run the below code cookie is returned as null.



HttpSession sess = req.getSession(false);
Cookie[] cook = req.getkookies();
if(cook != null){
for(int i=0;i<cook.length;i++)
{
if(cook[i].getName().equals("JSESSIONID'"))
System.out.println(" Session Id
="+cook[i].getValue());
}
}
if(sess == null)
{
System.out.println(" No session exists ...");
sess = req.getSession();
sess.setAttribute("Name","Dravid");
}else
{
System.out.println("Session prevails
.."+sess.getAttribute("Name"));
}
}
}
 
Vikrant Pandit
Ranch Hand
Posts: 245
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Senthil,

JSESSIONID cookie does gets created on the client browser . If you are using Mozilla then you can view all the cookies conviniently .

But the Container is stripping it off the request , before the request reaches reaches the Servlet. Kind of censoring you can say


You can use HttpSession.getId() method to view the JSESSIONID
 
Vikrant Pandit
Ranch Hand
Posts: 245
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Senthil,

I tried it with my piece of code and I did get the JSESSIONID cookie back.

So the JSESSIONID cookie does get back to servlet after all ... Sorry for the earlier speculative statement
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic