?? sessionlistener.java
字號:
package com.estore.struts.utils;import javax.servlet.http.HttpSession;import javax.servlet.http.HttpSessionEvent;import javax.servlet.http.HttpSessionListener;import com.estore.struts.entity.Cart;import com.estore.struts.entity.User;public class SessionListener implements HttpSessionListener{ /* * 在監聽到session被創建之后,就立即向session中添加一個購物車Car; */ public void sessionCreated(HttpSessionEvent arg0) { HttpSession session = arg0.getSession(); Cart cart=new Cart(); session.setAttribute("cart", cart); } /* * 在session被銷毀時一定要session中的內容清空; * 也就是在用戶點擊退出按鈕時,應完成的操作; */ public void sessionDestroyed(HttpSessionEvent arg0) { HttpSession session = arg0.getSession(); Cart cart = (Cart)session.getAttribute("cart"); session.removeAttribute("cart"); cart = null; User user = (User)session.getAttribute("user"); session.removeAttribute("user"); user = null; }}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -