如何正确设置session
import javax.servlet.http.HttpSession; //需要引入servlet-api.jar HttpSession session = request.getSession(); session.setAttribute("变量名", 值对象);
操作方法
- 01
HttpSession session = request.getSession();
- 02
session.setAttribute("变量名", 值对象);
- 03
session.getAttribute("变量名"); //此时取出来的是Object, 一般需要强转
- 04
session.removeAttribute("变量名");
- 05
session.invalidate(); //删除所有session中保存的键
赞 (0)