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

前端 未结 8 731
礼貌的吻别
礼貌的吻别 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 05:07

    First line will return the "session id" on server. The second line will return session object. So what will be printed on system.out would be request.getSession(false).toString();

    The default implementation of toString returns the "object id". Object id in terms of session is not the same as session id. Session could be serialized and replicated across the cluster so on each node of the cluster on each JVM it may have it's own object id (but should have same session id).

    Calling get session with boolean is explained here: http://docs.oracle.com/javaee/6/api/javax/servlet/http/HttpServletRequest.html#getSession(boolean)

提交回复
热议问题