Spring MVC Learning-Interceptors

Source: Internet
Author: User

 Public classGlobalinterceptorImplementsHandlerinterceptor { Public BooleanPrehandle (httpservletrequest request, httpservletresponse response, Object handler)throwsException {System.out.println ("Globalinterceptor Start Calling"); return true; }     Public voidPosthandle (httpservletrequest request, httpservletresponse response, Object handler, Modelandvi EW Modelandview)throwsException {//TODO auto-generated Method StubSystem.out.println ("Globalinterceptor in Call"); Modelandview.addobject ("MSG", "Globalinterceptor incoming"); }     Public voidaftercompletion (httpservletrequest request, httpservletresponse response, Object handler, Exception ex) throwsException {//TODO auto-generated Method StubSystem.out.println ("Globalinterceptor Call complete"); }}

To add a configuration:

Global URL interception:

< mvc:interceptors >      <!--  --    <class= " Com.rhythmk.web1.filter.GlobalInterceptor "  />  </MVC: Interceptors>

Specify the specification URL blocker:

<mvc:interceptors>      <!--using a bean to define a interceptor, directly defining the interceptor below the mvc:interceptors root will intercept all requests -    <Mvc:interceptor>          <mvc:mappingPath= "/uic/*"/>         <!--The expression defined below Mvc:interceptor is intercepted for a specific request . -        <Beanclass= "Com.rhythmk.web1.filter.GlobalInterceptor"/>      </Mvc:interceptor>  </mvc:interceptors> 

Spring MVC Learning-Interceptors

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.