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