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

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.

主站蜘蛛池模板: 杂多县| 龙山县| 蒙阴县| 本溪| 兴文县| 瑞安市| 和平区| 兴城市| 潮州市| 皮山县| 莱西市| 舞阳县| 博野县| 富平县| 靖远县| 当雄县| 娄烦县| 丰顺县| 甘洛县| 涿州市| 道孚县| 阳江市| 凤山市| 景宁| 油尖旺区| 新蔡县| 延津县| 常熟市| 称多县| 龙山县| 太湖县| 肃宁县| 平南县| 博罗县| 翁牛特旗| 永和县| 桃园县| 濮阳县| 辛集市| 浙江省| 循化|