aspose file tools*
The moose likes Servlets and the fly likes Session Tracking Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of EJB 3 in Action this week in the EJB and other Java EE Technologies forum!
JavaRanch » Java Forums » Java » Servlets
Bookmark "Session Tracking" Watch "Session Tracking" New topic
Author

Session Tracking

Sureshvasan Paramasamy
Greenhorn

Joined: May 25, 2004
Posts: 24
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

Joined: May 28, 2004
Posts: 20
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

Joined: May 28, 2004
Posts: 20
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

Joined: May 25, 2004
Posts: 24
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

Joined: Jan 15, 2004
Posts: 23
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
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: Session Tracking