"Oracle Java EE Programming Guide" 09-02: Session API-HttpSession Interface

HttpSession interface - how to get the type of interface objects

The Servlet API defined HttpSession interface, used to package the session object.

HttpSession is the interface, the object can not directly create new new, created session object is a container, a session object is to use the HttpServletRequest.

  • public HttpSession getSession (): Gets the current request associated with the session, if the session does not exist, create a new session object is returned.
  • public HttpSession getSession (boolean create): create If the parameter is true, the method is not equivalent to getSession argument. If the value of the parameter is create false, then if the session object associated with the current request does not exist, then return null, if present, directly back session object.
    JSP file using the session object's methods
  • JSP file has built-in object session, you can call any method HttpSession interface directly

HttpSession interface methods defined

HttpSession interface defines a set of methods

No. name Brief introduction Brief introduction
01 void setAttribute(String key,Object value) Object value stored in the form of key / value of.
02 Object getAttribute(String key) Gets an object value by key.
03 void removeAttribute(String key) Delete property by key.

Guess you like

Origin blog.csdn.net/goldentec/article/details/105336397