SPRINGMVC Login Blocker

Source: Internet
Author: User
Tags aop object object

Configuration and use of SPRINGMVC interceptors:
1. Customize the interceptor to implement the Handlerinterceptor interface.

Package Com.bybo.aca.web.interceptor;import Javax.servlet.http.httpservletrequest;import Javax.servlet.http.httpservletresponse;import Org.springframework.web.servlet.handlerinterceptor;import Org.springframework.web.servlet.modelandview;public class Login implements Handlerinterceptor {@Override public voi D aftercompletion (HttpServletRequest HttpRequest, HttpServletResponse HttpResponse, Object arg2, Exception arg3 ) throws Exception {} @Override public void Posthandle (HttpServletRequest arg0, HTTPSERVLETR Esponse arg1, Object arg2, Modelandview arg3) throws Exception {} @Override public boolean PR Ehandle (HttpServletRequest request, HttpServletResponse response, Object object) throws Exception {/*ht           Tpservletrequest HttpRequest = (httpservletrequest) request;       HttpServletResponse HttpResponse = (httpservletresponse) response;*/String urlstring = Request.getrequesturi ();             Olforum/forumlist.html Impersonation Login Page if (Urlstring.endswith ("forumlist.html")) {return true;               }//path requested by String Contextpath=request.getcontextpath (); /*httprequest.getrequestdispatcher ("/olforum/forumlist"). Forward (HttpRequest, httpresponse); */* Response.sendredirect (contextpath+ "/olforum/forumlist.html"); */Response.sendredirect (ContextPath + "/olForum/          Forumlist.html?login=aaa ");        return false;        /*httpresponse.sendredirect (Httprequest.getcontextpath () + "/olforum/forumlist.html"); return;*/}}

Configuration in 2:SPRINGMVC configuration file:

<?xml version= "1.0" encoding= "UTF-8"? ><beans xmlns= "Http://www.springframework.org/schema/beans" xmlns:       aop= "HTTP://WWW.SPRINGFRAMEWORK.ORG/SCHEMA/AOP" xmlns:context= "Http://www.springframework.org/schema/context" Xmlns:mvc= "Http://www.springframework.org/schema/mvc" xmlns:tx= "Http://www.springframework.org/schema/tx" xmln S:xsi= "Http://www.w3.org/2001/XMLSchema-instance" xmlns:p= "http://www.springframework.org/schema/p" Xsi:schema        location= "Http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop.xsd Http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd/HTTP Www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd/HTTP WWW.SPRINGFRAMEWORK.ORG/SCHEMA/MVC http://www.springframework.org/schema/mvc/spring-mvc.xsd/HTTP Www.springframework.org/schema/tx Http://www.springfraMework.org/schema/tx/spring-tx.xsd "> <!--Scan Controller (Controller layer injection)--<context:component-scan base- Package= "Com.bybo.aca.web.controller"/> <mvc:interceptors> <!--use beans to define a interceptor, directly defined in MVC:       The interceptor below the interceptors root will intercept all requests-<!--<bean class= "Com.bybo.aca.web.interceptor.Login"/> <mvc:interceptor> <!--interception:/** to intercept all controllers--<mvc:mapping path= "/**"/>
<!--do not intercept--<mvc:exclude-mapping path= "/index.html"/> <bean class= "com.b Ybo.aca.web.interceptor.Login "/> </mvc:interceptor> </mvc:interceptors>
<bean id= "Viewresolver" class= "Org.springframework.web.servlet.view.InternalResourceViewResolver" P:PR efix= "/web-inf/views/" p:suffix= ". jsp"/> </beans>

SPRINGMVC Login Blocker

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.