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

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.

主站蜘蛛池模板: 兴山县| 萨嘎县| 武宣县| 玛多县| 鲁山县| 宜州市| 兴安盟| 浦县| 增城市| 介休市| 富顺县| 黑龙江省| 东城区| 古蔺县| 山丹县| 东乡县| 沙河市| 龙江县| 鄄城县| 永州市| 江口县| 兴安盟| 阜平县| 宝丰县| 康乐县| 曲阳县| 印江| 南召县| 屏南县| 临夏市| 固原市| 阿合奇县| 甘孜| 久治县| 白水县| 绥中县| 梅河口市| 沁水县| 罗甸县| 确山县| 津南区|