I am developing Java Servlets. When you check if the user is registered, I want to check if the HTTP request has a valid session. To test this, I have 2 options:
(1)
protected void processRequest(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { HttpSession session = request.getSession(false); if (session != null) {
Since I pass false as an argument, a new session is not created if there is no longer a valid session, and the function returns null, which I can check.
Or me:
(2)
if (request.isRequestedSessionIdValid()) { // user is logged in ... }
Is there any difference, any advantage / disadvantage? Or are both functions more or less the same?
source share