创建:
protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
req.setCharacterEncoding("utf-8");
resp.setContentType("text/html;charset=utf-8");
//创建session
HttpSession session=req.getSession();
session.setAttribute("name", "name");
}
获取:
protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException
{
req.setCharacterEncoding("utf-8");
resp.setContentType("text/html;charset=utf-8");
HttpSession session=req.getSession();
PrintWriter out=resp.getWriter();
out.println(session.getAttribute("name"));
}
Comments | NOTHING