在servlet中获取session的方法是?

HttpSession.session = request.getSession();
还是HttpSession.session = request.getHttpSession(true);?

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

request.getSession() 自动调用了 request.getSession(true)而已
温馨提示:答案为网友推荐,仅供参考
第1个回答  2015-12-09
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);
}
相似回答