Difference between request.getSession().getId() and request.getSession(false)?

前端 未结 8 716
礼貌的吻别
礼貌的吻别 2021-01-31 04:08

What do these calls actually mean in terms of session?

System.out.println(\"print1: \"+request.getSession().getId());
System.out.println(\"print2: \"+request.get         


        
8条回答
  •  隐瞒了意图╮
    2021-01-31 04:53

        request.getSession()
    

    This method will check for the existing session;if exist its return otherwise create a new session for the request.

        request.getSession().getId();
    

    This will return the unique identifier for that session.

        request.getSession(false);
    

    This method takes the boolean value.This method check whether there is an existing session present for that user(request);if exist it return that session otherwise it return null i.e it won't create new session.

    Just to add more information for session.

        request.getSession(true);
    

    This method checks for the existing current session for that user(request) and if the session exist it will return that session or otherwise it create new session for that user.

        request.getSession() works like request.getSession(true)
    

    Reference : http://docs.oracle.com/javaee/1.4/api/javax/servlet/http/HttpServletRequest.html#getSession%28boolean%29

提交回复
热议问题