session何时创建

本文详细解释了在Java Web应用中,Session的工作机制及其如何在不同页面间维持用户会话状态。特别是针对HttpServletRequest.getSession(true)的作用及Session对象在JSP页面中的自动创建过程进行了深入探讨。
摘要由CSDN通过智能技术生成
没有 HttpServletRequest.getSession(true) ,Sesion是不会创建的, 即便Servlet又转发(或者重定向)到第二个页,只要第二个页(html)依然不是jsp页,Session就依然不会创建,如果是jsp则自动创建一个session对象,放到jsp的内置对象里面:jsp生成的servlet.java
//可以看到内置对象有session:
public void _jspService(HttpServletRequest request, HttpServletResponse response)
        throws java.io.IOException, ServletException {

    JspFactory _jspxFactory = null;
    PageContext pageContext = null;
    HttpSession session = null;
    ServletContext application = null;
    ServletConfig config = null;
    JspWriter out = null;
    Object page = this;
    JspWriter _jspx_out = null;
    PageContext _jspx_page_context = null;


    try {
      _jspxFactory = JspFactory.getDefaultFactory();
      response.setContentType("text/html;charset=UTF-8");
      pageContext = _jspxFactory.getPageContext(this, request, response,
      			null, true, 8192, true);
      _jspx_page_context = pageContext;
      application = pageContext.getServletContext();
      config = pageContext.getServletConfig();
      session = pageContext.getSession();
      out = pageContext.getOut();
      _jspx_out = out;

      out.write("\r\n");
      out.write("\r\n");
      out.write("\r\n");
      out.write("<html>\r\n");
      out.write("<head>\r\n");

String selfUrl = (String) SystemParameter.getValue(ConfigClassType.SYSTEM, "SSO", "SelfUrl");

      out.write("\r\n");
      out.write("</head>\r\n");
      out.write("<body>\r\n");
      out.write("<SCRIPT language=\"javascript\">\r\n");
      out.write("<!--\r\n");
      out.write("top.window.location = '");
      out.print( request.getContextPath());
      out.write("/loginindex.do';\r\n");
      out.write("//-->\r\n");
      out.write("</SCRIPT> \r\n");
      out.write("<!-- top.window.location = '");
      out.print( request.getContextPath() + selfUrl);
      out.write("';-->\r\n");
      out.write("<!-- top.window.location = '");
      out.print( request.getContextPath());
      out.write("/loginindex.do';-->  \r\n");
      out.write("</body>\r\n");
      out.write("</html>");
    } catch (Throwable t) {
      if (!(t instanceof SkipPageException)){
        out = _jspx_out;
        if (out != null && out.getBufferSize() != 0)
          out.clearBuffer();
        if (_jspx_page_context != null) _jspx_page_context.handlePageException(t);
      }
    } finally {
      if (_jspxFactory != null) _jspxFactory.releasePageContext(_jspx_page_context);
    }
  }
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值