拦截器(配置)
来源:互联网 发布:宾馆网络解决方案 编辑:程序博客网 时间:2024/06/08 19:51
定义
DispatcherServlet收到请求之后,如果有拦截器,则先执行,拦截器的方法,然后再执行处理器的方法。
注:
过滤器属于Servlet规范,而拦截器属于Spring框架。
如何写拦截器?
step1. 写一个java类,实现HandlerInterceptor接口。
step2. 在拦截器方法里面,实现拦截处理逻辑。
step3. 配置拦截器。
public class SomeInterceptor implements HandlerInterceptor{ /** * 请求处理完毕,最后执行的方法。 * (了解) * arg3:处理器所抛出的异常。 */ public void afterCompletion( HttpServletRequest arg0, HttpServletResponse arg1, Object arg2, Exception arg3) throws Exception { System.out.println("afterCompletion()"); } /** * 处理器(Controller)方法已经执行完毕, * 正准备将处理结果(ModelAndView)返回 * 给DispatcherServlet之前,执行postHandle * 方法。 * 注: * 可以在该方法里面,修改处理结果。 */ public void postHandle( HttpServletRequest arg0, HttpServletResponse arg1, Object arg2, ModelAndView arg3) throws Exception { System.out.println("postHandle()"); } /** * DispatcherServlet会先调用拦截器的 * preHandle方法,如果该方法返回值为 * true,则继续向后调用;否则,中断请求 * (不再向后调用)。 * (了解) * arg2:是一个描述处理器方法的对象。 */ public boolean preHandle( HttpServletRequest arg0, HttpServletResponse arg1, Object arg2) throws Exception { System.out.println("preHandle()"); return true; }}
阅读全文
0 0
- 拦截器(配置)
- 配置自定义拦截器(全局配置)
- Spring boot配置拦截器(十四)
- spring拦截器配置
- 创建拦截器配置
- Struts2拦截器配置
- struts2 拦截器配置
- Struts2配置拦截器
- 配置struts2拦截器
- Struts2拦截器配置
- struts2 拦截器配置
- springmvc 拦截器配置
- 拦截器配置
- Struts2拦截器配置
- struts2拦截器配置
- struts2 拦截器配置
- spring拦截器配置
- Struts2拦截器配置
- 求一个数组的第K大的数
- 初入MyBatis框架<一>
- python中的字符数字之间的转换
- python调用c
- Java如何输入不确定长度的数组
- 拦截器(配置)
- 97. Interleaving String
- 素数判断的三种方法以及简单实现!
- 关于STm32加密【转】
- struts2标签以及获取parameter,request,session,application中的值
- 谈谈个人网站的建立(一)——建站历史和技术架构
- hdu 1114 Piggy-Bank 完全背包
- 《软技能-代码之外的生存指南》读后感
- 求最大子列和 (连续子串的最大值)