Realize Workarea logout when session

xiaoxiao2021-03-06  113

1, problem

l After using the specific Workarea login, the system will lock the Workarea to prevent the same Workarea from re-login.

l However, after specific Workarea login, it may have an abnormal exit, such as moving to other websites in the middle, because logout does not perform logout, causing locking Workarea to not release, so that it is not reusable

l Therefore, you need to perform logout through some way, release the locking Workarea

2, solve ideas

Execute Workarea's logout when it is exposed to SESSION

l Set the failure time of the session (see "Using Session in APC")

l Use the session variable listener to monitor the removal event of the session variable

l When Workarea login (now you have created a session), set the Workarea value to the session variable.

l When session fails, the session variable will be removed, resulting in removal events.

l In removing the event callback function, get the Workarea value via the session variable, logout

l All operations after session failure are redirected to the first screen.

l You can determine the session failure by the session variable value of null.

3, auxiliary class

l SessionUtil: Access operation for session variables

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 getsession (DispatchContext context) {

Return ((httpsessionprofile) context.getationsProfile ()). getsession ();

}

Public Static Object GetaTribute (DispatchContext Context, String Name) {

Try {

Return getsession (context) .GetaTribute (name);

} catch (IllegalStateException ex) {

Return NULL;

}

}

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 SessionattributeListener: session variable listener, used to monitor the removal event of the session variable (need to configure the listener, see "Using session in APC")

Package com.fujitsu.eframe.eftool;

Import javax.servlet.http.httpsessionatTributelistener; import javax.servlet.http.httpsessionBindingEvent;

Public class sessionattributeListener implements httpsessionattributeListener {

Public void attributeadded (httpsessionBindingEvent evenet) {

System.out.print (event.getname () "Added!");

System.out.println ("Value =" Event.GetValue ());

}

Public void attributemoved (httpsessionBindingEvent evenet) {

IF (Event.getName (). Equals ("Workarea")) {

System.out.Println ("Workarea Removed!");

String Workarea = (String) Event.getValue ();

System.out.println ("Workarea =" Workarea;

IF (Workarea! = NULL) {

Workspaceinf wsi = workspace.getInstance ();

WSI.logout (Workarea);

}

}

}

Public void attributeced (httpsessionBindingEvent event) {

}

}

4, specific implementation

(1) When in Workarea login, set the Workarea value to the session variable in Workarea.

... // Save the Workarea value to the Name variable

SessionUtil.SetaTribute (Context, "Workarea", Name;

(2) For each action (except the first page, see later), it is determined whether the session expires, if it is invalid, redirect to the first page (recommended to package this feature)

...

EFT_0115Bean EFT_0115Bean = New EFT_0115Bean ();

String Workarea = (string) sessionutil.getattribute (Context, "Workarea");

IF (Workarea == Null) {

String username = ""

Listbox lb = EFT_0115Bean.getDirlist ();

Workspaceinf wsi = workspace.getInstance ();

WSI.FIRSTWS ();

While (! wsi.islastws ())

{

IF (! wsi.iswsused ())

{

Username = wsi.getwsname ();

Lb.Add (username);

}

WSI.NEXTWS ();

}

System.out.println ("Redirect To First Page!);

EFT_0115Bean.setverb ("reqmode");

Context.setResponsebean ("Body", EFT_0115Bean;

Return;

}

...

(3) Processing of the first picture

Since the first screen does not involve the login and logout of Workarea, other session variables need to be used to determine the failure of the session.

l Set the session variable in the startup () method

SessionUtil.SetaTRibute (Context, "FirstPage", "Yes");

l All actions of the first screen, use the previous similar approach to determine whether the session invalid, if it is invalid, redirect to the first page, distinguish:

Ø session variable is firstpage instead of Workarea

Ø Reset the value of firstpage before redirect

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

New Post(0)