开发者

Override jspDestroy() to close Session in Java EE

开发者 https://www.devze.com 2023-03-09 01:27 出处:网络
I want to remove my session when I close the window of my application. I\'m trying to override jspDestroy() with session.set开发者_C百科Attribute(\"user\",null); but it doesn\'t work.I think you have

I want to remove my session when I close the window of my application. I'm trying to override jspDestroy() with session.set开发者_C百科Attribute("user",null); but it doesn't work.


I think you have misunderstood the purpose of jspDestroy(). This method is the equivalent of the Servlet destroy() method. From the sample in the JSP 2.2 spec:

/** An example of a superclass for an HTTP JSP class */
abstract class ExampleHttpSuper implements HttpJspPage {

 /** What you are overriding */
 public void jspDestroy() {}

 final public void destroy() {
   jspDestroy();
 }

 final public void service(ServletRequest req, ServletResponse res)
        throws ServletException, IOException {
 //remainder elided

This method will be invoked when the JSP is no longer servicing requests. It does not have a 1-1 relationship with user sessions.

Because the browser does not maintain an open connection with the server, terminating a session on browser close is a more involved topic. You can read about some approaches in the answers to these similar questions.

0

精彩评论

暂无评论...
验证码 换一张
取 消