What if you only want a pre-existing session?

HttpSession session = request.getSession(false);<%--Passing "false" means the method returns a pre-existing session or null if there was no session associated with this client.--%>

if(session == null){
     session = request.getSession();
}

你可能感兴趣的:(session,getSession)