在servlet中获取session的方法是?

来源:百度知道 编辑:UC知道 时间:2024/09/25 19:19:04
HttpSession.session = request.getSession();
还是HttpSession.session = request.getHttpSession(true);?

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);
}

HttpSession session = request.getSession();
这样,没有.

request.getSession() 自动调用了 request.getSession(true)而已