How do I know the user closes the browser and end the session?

xiaoxiao2021-03-06  167

J2EE application How to reclaim resource case description after the user session is completed: WebLogic Server 8.1 SP2 Technical Solution: Servlet, JSP, EJB, JDBC Connction Pool Working Principle: When you use a browser to log in to the system, JSP is established through JavaBean Connect to the EJB call, and the EJB object is connected to the background database via the Connection pool. After the user is legally logged in, the method of calling the EJB object through the JSP JavaBean completes the operation and query of the background database, and returns the query result to the user browser by JSP. To solve the problem: When the user is abnormal logout (session timeout, or the user directly closes the browser), the relevant resources (such as JDBC Connection Pool), if the EJB object (such as JDBC Connection Pool) does not release, if this happens, the relevant resources will be consumed The possibility of how to release the resources owned by the EJB object in this case. Solution: Use Listener Servlet implemented HttpSessionListener interface, which has the following two methods: triggered void sessionDestroyed (HttpSessionEvent se) when public class ServletListener extends HttpServlet implements HttpSessionListener {void sessionCreated (HttpSessionEvent se) {} // // When session creation when Trigger {// Release EJB object at the end of the session Try {se.getations; setttribute ("ejbeq", null); se.getsession () (). Removeattribute ("EJBEQ");} catch (Exception EX) { System.out.println (EX.TOString ());}}} When the session is timeout, the web container calls the sessiondestroyed () method. When the method is called, the EJB container calls the ejbremove () method to implement the resource owned by the EJB object. . The Listener Servlet deployment file Web.xml is as follows: servletlistener 1

转载请注明原文地址:https://www.9cbs.com/read-128100.html

New Post(0)