• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Session Tracking

 
Greenhorn
Posts: 24
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Greenhorn
Posts: 20
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Greenhorn
Posts: 23
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
We're being followed by intergalactic spies! Quick! Take this tiny ad!
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic