P
P
P_Alexander2018-01-16 17:30:36
Java
P_Alexander, 2018-01-16 17:30:36

Why is a session immediately created in a webapp?

Why doesn't the if block work???
how does the session exist?

@WebServlet(name = "WarmStar", urlPatterns = "/warmStar")
public class WarmStar extends HttpServlet {
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {

    }

    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        HttpSession httpSession = request.getSession();
        if(httpSession == null){
            System.out.println("dsdsdsdsdsdsdsdsdsdsdsssdsdsdsdsdsds");
        }

        System.out.println("111 " + request.getContextPath() + " dddddd " + request.getRequestURI() + "rrr " + request.getServletPath());
        System.out.println("TYTYTYYTY");
        request.getRequestDispatcher("index.jsp").forward(request,response);
    }
}

Answer the question

In order to leave comments, you need to log in

1 answer(s)
D
Dmitry Roo, 2018-01-16
@P_Alexander

Probably because if a get request (the doGet method) comes in, then it comes already inside the session?
And it comes with parameters: HttpServletRequest request, HttpServletResponse response
Well, further according to the scheme: HttpSession httpSession = request.getSession();

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question