springmvc中拦截器使用
来源:互联网 发布:win7卸载不了软件 编辑:程序博客网 时间:2024/06/05 16:42
springmvc中拦截器使用
1.contorller中:
@RequestMapping("/testinterceptor")public String testinterceptor(HttpServletRequest request){
System.out.println("执行了controller中的testinterceptor方法");
return "success";
}
2.在interceptor包中创建MyInterceptor类实现接口HandlerInterceptor
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.springframework.ui.ModelMap;
import org.springframework.web.context.request.WebRequest;
import org.springframework.web.context.request.WebRequestInterceptor;
import org.springframework.web.servlet.HandlerInterceptor;
import org.springframework.web.servlet.ModelAndView;
public class MyInterceptor implements HandlerInterceptor {
@Override
public void afterCompletion(HttpServletRequest arg0, HttpServletResponse arg1, Object arg2, Exception arg3)
throws Exception {
// TODO Auto-generated method stub
System.out.println("afterCompletion");
}
@Override
public void postHandle(HttpServletRequest arg0, HttpServletResponse arg1, Object arg2, ModelAndView arg3)
throws Exception {
// TODO Auto-generated method stub
System.out.println("postHandle");
}
@Override
public boolean preHandle(HttpServletRequest arg0, HttpServletResponse arg1, Object arg2) throws Exception {
// TODO Auto-generated method stub
System.out.println("preHandle");
return true;
}
}
//打印顺序:preHandle-->执行了controller中的testinterceptor方法-->postHandle-->afterCompletion
<mvc:interceptors>
<!-- 过滤所有的请求 -->
<!-- <bean class="com.springmvc.interceptor.MyInterceptor"/> -->
<!-- 过滤特定路径的请求,路径要从根路径开始设置-->
<mvc:interceptor>
<mvc:mapping path="/test1controller/testinterceptor.do"/>
<bean class="com.springmvc.interceptor.MyInterceptor"/>
</mvc:interceptor>
</mvc:interceptors>
0 0
- SpringMVC中使用拦截器
- springmvc中拦截器使用
- 【springMVC】springMVC中使用Interceptor拦截器
- SpringMVC中使用Interceptor拦截器
- SpringMVC中使用Interceptor拦截器
- SpringMVC中使用Interceptor拦截器
- SpringMVC中使用Interceptor拦截器
- SpringMVC中使用Interceptor拦截器
- SpringMVC中使用Interceptor拦截器
- SpringMVC中使用Interceptor拦截器
- SpringMVC中使用Interceptor拦截器
- SpringMVC中使用Interceptor拦截器
- SpringMVC中使用Interceptor拦截器
- SpringMVC中使用Interceptor拦截器
- SpringMVC中拦截器的使用
- SpringMVC中使用Interceptor拦截器
- SpringMVC中使用Interceptor拦截器
- SpringMVC中使用Interceptor拦截器
- HDU 1134 Game of Connections (高精度卡特兰数)
- PL/SQL Developer登录提示 ORA-12541:TNS:无监听程序(转载)
- Swift程序入口深度分析
- ThinkPHP自动化为已经上传的图片添加「 响应式」水印(数据库字段部分)
- ListView的性能优化及进阶
- springmvc中拦截器使用
- 南阳 oj 448 光棍的yy
- Matlab Tricks(十四) —— 句柄(handle)(图形对象属性的读取与修改)
- Android模拟器时提示"No system images installed for this target"的问题
- 240. Search a 2D Matrix II
- 回归和梯度下降
- springmvc中日期.float类型转换简便方式
- 从GNU Prolog转换到SWI Prolog
- javascript 笔记