First of all, your testing methodology is completely incorrect.
if (request.getSession() == null){ System.out.println("No session."); } else { System.out.println("Session already exists."); }
Please read the javadoc method carefully with no getSession() arguments. You will realize that it never returns null .
Coming back to a specific problem, by default, JSF will actually auto-create a session because the state of the JSF view should be stored there. If you set the JSF state preservation parameter to client instead of server , then it will not be saved in the session and, therefore, the session should not be created.
<context-param> <param-name>javax.faces.STATE_SAVING_METHOD</param-name> <param-value>client</param-value> </context-param>
In the upcoming JSF 2.2, you can also put a bean in the request area and use <f:view transient="true"> to go completely stateless. This is for the current version of JSF 2.1, available only with Mojarra 2.1.19. See Also, for example. this blog is from one of the Mojarra developers.
source share