如何在servlet中使用session????

来源:百度知道 编辑:UC知道 时间:2024/06/24 00:34:15
顶头引用了HttpSession

doPost HttpSession hs =new HttpSession();

最后一段报错“can't instantiate the type HttpSession”

该怎么正确使用session?!

public void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {

response.setContentType("text/html");
PrintWriter out = response.getWriter();
//通过request得到session
request.getSession().setAttribute(arg0, arg1);
}

request.getSession();

HttpSession hs =new HttpSession();
hs.setAttribute(key, value);