java session management

后端 未结 3 1515
-上瘾入骨i
-上瘾入骨i 2020-12-18 11:39

I am working on a small webapp for fun, using just Java Servlets at the moment. I have two pages, test1 and test2. At the moment I am creating a new session in test1 like th

3条回答
  •  無奈伤痛
    2020-12-18 12:16

    If you want to restrict the flow to ensure that test1 comes before test2, have test1 put an attribute value in the session that says it's been visited, and test for that attribute value in test2. If the value is not there, have test2 redirect to test1.

    In test1, do this:

    HttpSession session = request.getSession();
    session.setAttribute("test1",true);
    

    Then, in test2, you can do this:

    HttpSession session = request.getSession();
    if (session.getAttribute("test1") == null){
        response.sendRedirect("test1");
        return;
    }
    

提交回复
热议问题