Edit Edit

Java Servlet FAQ


How do you use sessions with servlets?


1) get the session with HttpServletRequest's getSession():

public HttpSession getSession(boolean create)

where the create flag is true if you want to create a session if one does not already exist

2) store your session data into the session with HttpSession's putValue:

public void putValue(String name, Object value)

3) in subsequent requests, you can get the session data back by calling HttpSession's getValue()

public Object getValue(String name)

You can get a list of all the session data names by calling getValueNames():

public String[] getValueNames():



Last updated 12/19/1999 05:07:54 PM