Can I turn off the HttpSession in web.xml?

前端 未结 9 1056
深忆病人
深忆病人 2020-11-27 14:29

I would like to eliminate the HttpSession completely - can I do this in web.xml? I\'m sure there are container specific ways to do it (which is what crowds the search result

9条回答
  •  执念已碎
    2020-11-27 14:40

    One cannot avoid the session creation. But you can check if you violate your own requirement at the end of a request cycle. So, create a simple servlet filter, which you place as first and after chain.doFilter throw an exception if a session was created:

    chain.doFilter(request, response);
    if(request.getSession(false) != null)
        throw new RuntimeException("Somewhere request.getSession() was called");
    

提交回复
热议问题