Java HttpSession

前端 未结 5 904
眼角桃花
眼角桃花 2021-02-02 16:51

Is HttpSession in java servlet is created only after

HttpSession s = request.getSession();

?

In my code I didn\'t write that, but when

5条回答
  •  逝去的感伤
    2021-02-02 17:38

    To make it complete:

    • session is not created, unless you call request.getSession(), in your servlet, use request.getSession(false) to get existing session without creating new session
    • if you use JSP page, session is automatically created for you - variable session - unless you specify <%@ page session="false" %>
    • even if your session is created automatically, you can use session.isNew() to find out, if it has been newly created

提交回复
热议问题