SSH2 Landing Interception configuration (if logged in, then jump to the user needs to visit the page, if not logged in, go directly to the login page)

Source: Internet
Author: User

Struts.xml configuration:<!--Custom user Login Interceptor--><!--for other struts profiles that require login interception, if you inherit "default", you do not need to configure it, you can implement the interceptor directly through inheritance, if you do not inherit "Default", you need to configure the login blocker, configure the same way as here, if an action does not need to intercept, then add the default interceptor under the action (<intercentor-ref name= "Defaultstack"/> --><!--Description: Logininterceptor: Can be arbitrarily taken, and <intercentor-ref name= "Logininterceptor"/> In the same line mydefault: free to take, and rewrite the default interceptor is the same as the name can be defaultstack: The default interceptor, you must write--><intercentors><intercentor class= "Interceptor Java file path" Name= " Logininterceptor "/><intercentor-stack name=" Mydefault "><intercentor-ref name=" DefaultStack "/>< Intercentor-ref name= "Logininterceptor"/></intercentor-stack></intercentors><!--overriding the default interceptor-- <default-interceptor-ref name= "Mydefault"/><!--define global variables, jump to login page opslogin.jsp for login page--><global-results ><resutl name= "Login" type= "redirect" >/opsLogin.jsp</result></global-results>
//Interceptor Java code import java.util.map;import Com.opensymphony.xwork2.action;import Com.opensymphony.xwork2.actioncontext;import Com.opensymphony.xwork2.actioninvocation;import com.opensymphony.xwork2.interceptor.abstractinterceptor;/** * User Login Blocker */public class Logininterceptor extends Abstractinterceptor{public string Intercept (Actioninvocation invaction) throws exception{// Gets the user in session Idactioncontext CTX = Invocation.getincovationcontext (); map<string,object> session = Ctx.getsession (); Object object = Session.get ("id");//If it is not empty, struts will continue to execute if (Object!). = null) {return Invocation.invoke ();} else{//if empty, jump directly to the login page return action.login;}}} 
User Login Action Code public String login () {///user information based on username and password user = Opsusermanager.findbynameandpwd (name,password); If the queried user information is not empty, the user ID is stored in the session and jumps to the main page if (user! = null) {HttpServletRequest request = Servletactioncontext.getrequest (); map<string,object> map = Actioncontext.getcontext (). getsession (); Map.put ("id", User.getid ()); return SUCCESS;} else{//if the query is not reached, then jump to the login page return ERROR;}


SSH2 Landing Interception configuration (if logged in, then jump to the user needs to visit the page, if not logged in, go directly to the login page)

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.