Win a copy of Design for the Mind this week in the Design forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Session Tracking

 
Sureshvasan Paramasamy
Greenhorn
Posts: 24
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi every body

What is the different between session.req.getSession(true);
and session.req.getSession();
whic is used to crate a servlet?

vasan
 
jai gurudev
Greenhorn
Posts: 20
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Sureshvasan Paramasamy:
Hi every body

What is the different between session.req.getSession(true);
and session.req.getSession();
whic is used to crate a servlet?

vasan
 
jai gurudev
Greenhorn
Posts: 20
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Sureshvasan Paramasamy:
Hi every body

What is the different between session.req.getSession(true);
and session.req.getSession();
whic is used to crate a servlet?

vasan




ReplY:

Creating a session couldn't be simpler. Off the HTTPServletRequest object, req, call:



HttpSession theSession = req.getSession(true);

That will get the current HTTPSession for the client, or create one if it doesn't already exist. If the argument value to getSession() was false, no session will be created if one doesn't already exist. The following CreateSession servlet illustrates how to create a session and glean some important session statistics such as creation time, last access time, the maximum lifetime of a session in seconds and most importantly, the session id that is used to uniquely identify a client's session.
 
Sureshvasan Paramasamy
Greenhorn
Posts: 24
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks

This is what i want if in the login servlet i created a session
session=req.getSession(true); and set a value like session.setAttribute("WAS",strWAS)

if i want to get value in the next servlet ,then again i want to create a session or just i can use String strWAS2=session.getAttribute("WAS");

pls explain it
 
Siyaa Hoffman
Greenhorn
Posts: 23
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Sureshvasan,

In the next servlet, if the next servlet is invoked in the same session, you would be able to just do session.getAttribute(attributeName) to get the value. You do not need to create any new session in that servlet.

But if the next servlet is not invoked in the same session, you cannot access the attribute defined in the session scope. If that is a possibility, you need to see which scope would suit you. The available scopes are -

request
session
application
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic