struts2 session Blocker

Source: Internet
Author: User
Today found Servletresponse.sendredirect (path+ "/login.jsp") when using Sessionfilter to filter the session, sometimes not jump, can use interceptors to implement.
Added in Struts.xml:
Java code   <!--  Define a author interceptor and define a default interceptor  -->       < interceptors>                < Interceptor name= "Authorlogin"  class= "Com.rating.joyintech.action.AuthorizationInterceptor"/>               <interceptor-stack name= "Mystack" >                    <interceptor-ref name= "Defaultstack"/>                    <interceptor-ref name= "AuthorLogin"/>                 </ interceptor-stack>            </interceptors>       &NBSp;      <default-interceptor-ref name= "MyStack"/>           <global-results>             <result name= "Nosession" >/login.jsp</result>        </global-results>  
The corresponding interceptor code is as follows:
Java code   package com.rating.joyintech.action;      import java.util.map;       import javax.servlet.http.httpservletrequest;      import  org.apache.struts2.servletactioncontext;      import  com.opensymphony.xwork2.actioninvocation;   import  com.opensymphony.xwork2.interceptor.abstractinterceptor;      public class  authorizationinterceptor extends abstractinterceptor{            @Override        public string intercept (Actioninvocation ai)  throws Exception {           // todo  Auto-generated method stub           map  session = ai.getinvocationcontext (). GetSession ();   &NBSP;&NBSP;&NBSP;&NBsp;    httpservletrequest request = servletactioncontext.getrequest ();            if (Session.get ("UserInfo") ==null &&  request.getrequesturi (). IndexOf ("login") ==-1) {//login.action do not intercept                 return  "Nosession";                           } else{               return ai.invoke ();           }       }             } 



Reprinted from: http://corejava5.iteye.com/blog/1213725

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.