java HttpServletRequest 獲取和設置session

使用 HttpServletRequest 對象操作session,先要通過

getSession()
獲取session,再用以下函數進行操作。

1、設置指定名稱的session屬性值。

void setAttribute( String name, String value )

 request.getSession().setAttribute("username", "name");

2、獲取與指定名字相關聯的session屬性值。

Object getAttribute( String name )

request.getSession().getAttribute("username");

3、設置session的有效期。

void setMaxInactiveInterval( int interval ) ;

4、移除指定名稱的session屬性。
 void removeAttribute( String name ) ;




發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章