1, use session
l As long as you get an HTTPSESSSION object, you can manage and use the session.
l In order to follow the MVC mode, the use of session should be implemented in Handler.
l In Handler, you can use the DispatchContext this context environment to get httpsession objects.
l The following is a tool class that encapsulates simple use of Session:
Package com.fujitsu.eframe.eftool;
Import javax.servlet.http.httpsession;
Import com.fujitsu.uji.dispatchContext;
Import com.fujitsu.uji.http.httpsessionprofile;
PUBLIC CLASS sessionUtil {
PRIVATE Static httpsession session;
Private static httpsession getsession (DispatchContext context) {
IF (session == null) {
Session = (httpsessionprofile) context.getationsProfile ()). getsession ();
}
Return session;
}
Public Static Object GetaTribute (DispatchContext Context, String Name) {
Return getsession (context) .GetaTribute (name);
}
Public Static Void SetAttribute (DispatchContext Context, String Name, Object Value) {
GetSession (Context) .SetaTRibute (name, value);
}
Public Static Void Settimeout (DispatchContext Context, Int Seconds) {
GetSession (Context) .SetMaxInactiveInterVal (Seconds);
}
}
l Here the most important thing is to use the API provided by the APC to get httpsession objects.
Ø Get the HttpSessionProfile object (forced conversion because sessionprofile is the abstract parent class of HttpSessionProfile)
Ø The httpsession object is obtained by the GetSession () method of HttpSessionProfile.
l Also note that the timeout time specified in the setTimeout () method is in seconds.
l This can use session in Handler, for example:
SessionUtil.SetaTribute (Context, "Workarea", Name;
2, monitor session
l You can implement the HTTPSessionListener interface to achieve the creation and destruction of the SESSION. The following is a simple framework:
Package com.fujitsu.eframe.eftool;
Import javax.servlet.http.httpsessionEvent;
Import javax.servlet.http.httpsessionListener;
Public Class SessionListener Implements HttpSessionListener {Public Void Sessioncreated (httpsessionever
System.out.println ("Session Created!");
}
Public void sessiondestroyed (httpsessionever se) {
System.out.println ("session destroyed!");
}
}
l HttpSessionListener interface provides sessioncreated () and sessionDestroyed () two methods, which are called before the session created and the session destroyed
l Therefore, you can do some of the initialization work created after SessionCreated () method; and do some SESSIONDESTROYED () methods to do some session destruction clear work
l To register your listener, you can configure it in Web.xml:
XML Version = "1.0" encoding = "UTF-8"?>
context-param>
com.fujitsu.eframe.eftool.SessionListener
listener-class>
listener>
session-config>
taglib>
web-app>
l APC defaults using web-app_2_2.dtd, does not support
l Use the
l The above example also uses the