Java implements an account that can only log on to the same region, go offline elsewhere, and go offline in java

Source: Internet
Author: User

Java implements an account that can only log on to the same region, go offline elsewhere, and go offline in java

In fact, there are a lot of methods, and I am ugly.

Use to understand the four major scopes of java.

Idea: understand the key to the Four Scopes of java.

First place login:

1. Get the SessionId and username of the request.

2. Save the SessionId to the application and the user name to the current session.

ActionContext ac = ActionContext. getContext (); Map <String, Object> applicationMap = ac. getApplication (); Map <String, Object> sesisonMap = ac. getSession ();
// The sessionId String currentSeesionId = getRequest (). getSession (). getId (); applicationMap. put (loanUserE. getUname (), currentSeesionId); sesisonMap. put (CommonVar. SSO_LOGIN_NAME_KEY, loanUserE. getUname ());

 

Second place login:

1. Get the SessionId of the browser and the username for login

2. Get the keyword corresponding to the user name in the current session, and use the keyword to get the SessionId in the application,

For comparison, jump to login if they are not equal.

Interceptor:

/** Get the initialization parameter */ActionContext actionContext = arg0.getInvocationContext ();/** HttpServletRequest parameter */HttpServletRequest request = (HttpServletRequest) actionContext. get (StrutsStatics. HTTP_REQUEST);/** HttpServletResponse parameter */HttpServletResponse response = (HttpServletResponse) actionContext. get (StrutsStatics. HTTP_RESPONSE);/** Session parameter */Map <String, Object> sessionMap = actionContext. getSessi On (); Map <String, Object> appcationMap = actionContext. getApplication (); String loginName = null; // sessionId String sessionId = null in the context Object; if (! SessionMap. isEmpty () {loginName = (String) sessionMap. get (CommonVar. SSO_LOGIN_NAME_KEY);} if (null! = LoginName) {sessionId = (String) appcationMap. get (loginName);} // sessionId of the current session String currentSessionId = request. getSession (). getId (); if (! CurrentSessionId. equals (sessionId) {return "loanUserLogin ";}

 

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.