2017.3.31 Spring MVC Tutorial (iii) Request mapping (static file access, interceptors)

Source: Internet
Author: User
Tags spring mvc tutorial

Learning Blog: http://elf8848.iteye.com/blog/875830/

Version used in my project: 4.2.0. Blog time earlier, 11, learning is Spring3 MVC. I do not know if there is any change in the version of the larger features.

Spring MVC Tutorial (iii) interceptors

Interceptors in 1.Spring

(1) Interceptor interface

Spring provides an interceptor interface. Implement this interface or inherit this class, you can implement your own interceptor.

Org.springframework.web.servlet.  handlerinterceptor interface 2 Org.springframework.web.servlet.handler.  Handlerinterceptoradapter Adapter 
Implements   handlerinterceptor// slightly   

Handlerinteceptor has 3 methods: preprocessing, post-processing (call service and return Modelandview, but no page rendering), return processing (page already rendered).

The object handler in the parameter is the next interceptor.

1//Action before executing2PublicBooleanPrehandle(HttpServletRequest request,httpservletresponse response, Object handler);34 // perform 5 public void   posthandle  (httpservletrequest Request,httpservletresponse response, Object handler,  Modelandview  Modelandview); 6 7 // Last execution, can be used to release resources 8 public void   aftercompletion  ( HttpServletRequest request,httpservletresponse response,  object Handler  , Exception ex)            

(2) The execution process of the Interceptor

2017.3.31 Spring MVC Tutorial (iii) Request mapping (static file access, 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.