官术网_书友最值得收藏!

Configuring custom interceptors

While servlet filters are a part of the Servlet API and have nothing to do with Spring besides being automatically added in the filter chain --Spring MVC provides us with another way of wrapping web requests: HandlerInterceptor. According to the documentation, HandlerInterceptor is just like a filter. Instead of wrapping a request in a nested chain, an interceptor gives us cutaway points at different phases, such as before the request gets handled, after the request has been processed, before the view has been rendered, and at the very end, after the request has been fully completed. It does not let us change anything about the request, but it does let us stop the execution by throwing an exception or returning false if the interceptor logic determines so.

Similar to using filters, Spring MVC comes with a number of premade HandlerInterceptors. The commonly used ones are LocaleChangeInterceptor and ThemeChangeInterceptor; but there are certainly others that provide great value. So let's add LocaleChangeInterceptor to our application in order to see how it is done.

主站蜘蛛池模板: 汉沽区| 县级市| 黔江区| 瑞丽市| 资阳市| 淮滨县| 松滋市| 罗山县| 独山县| 荆门市| 阳朔县| 武城县| 平泉县| 通山县| 崇礼县| 宣威市| 永宁县| 隆安县| 文山县| 东明县| 葵青区| 杨浦区| 景德镇市| 体育| 大关县| 高碑店市| 南召县| 宁国市| 丹江口市| 囊谦县| 馆陶县| 盐山县| 山丹县| 错那县| 深泽县| 玉树县| 宜兰市| 临洮县| 道孚县| 方城县| 绥中县|