SPRINGMVC's mvc:exclude-mapping not intercept a request

Source: Internet
Author: User

When using Springmvc Yes, a Session interceptor is configured to intercept whether the user is logged in, but when the user accesses the login page and registers the page, it is not necessary to intercept it, then this tag is needed to <mvc:execlude-mapping/>.

The code comes first:

<!--configuring interceptors for session validation -    <!--If there are multiple interceptors that meet the requirements of interception processing, they are executed according to the order of the configuration -    <mvc:interceptors>        <Mvc:interceptor>            <!--interception of all requests, this must be written in front, that is, written on the "Do not intercept" above -            <mvc:mappingPath="/**" />            <!--but excluding the following, that is, not intercepting the request -            <mvc:exclude-mappingPath= "/login.html" />            <mvc:exclude-mappingPath= "/account/login.do" />            <mvc:exclude-mappingPath= "/account/regist.do" />            <Beanclass= "Com.msym.cloudnote.interceptors.SessionInterceptor" />        </Mvc:interceptor>    </mvc:interceptors>

One thing to note:

is the above "intercept" and "Do Not intercept", "intercept" the label to write on it.

Code for the Interceptor:

 Packagecom.msym.cloudnote.interceptors;Importjavax.servlet.http.HttpServletRequest;ImportJavax.servlet.http.HttpServletResponse;Importjavax.servlet.http.HttpSession;ImportOrg.springframework.web.servlet.HandlerInterceptor;ImportOrg.springframework.web.servlet.ModelAndView;/*** Determine if the interceptor is logged in *@authorthe ape Dream on the codehttp://www.cnblogs.com/daimajun/ */ Public classSessioninterceptorImplementsHandlerinterceptor { Public voidPosthandle (httpservletrequest request, httpservletresponse response, Object handler, Modelandview Modeland View)throwsException {} Public voidaftercompletion (httpservletrequest request, httpservletresponse response, Object handler, Exception ex) 
     throwsException {} Public BooleanPrehandle (httpservletrequest req, httpservletresponse Res, Object Handel)throwsException {HttpSession session=req.getsession (); //get specific data from the sessionObject obj = Session.getattribute ("name"); if(obj = =NULL) {            //not logged in, redirect to login pageRes.sendredirect (Req.getcontextpath () + "/login.html"); return false; }        //logged in, continue to call back        return true; }}

SPRINGMVC's mvc:exclude-mapping not intercept a request

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.