6、spring拦截器
来源:互联网 发布:移动通话记录查询软件 编辑:程序博客网 时间:2024/06/06 00:36
1.需求:在部分需要判断用户是否存在的情况下访问一些页面,如果用户不是登录状态则需要先登录。
package com.iflysse.bbs.interceptor;import javax.servlet.http.HttpServletRequest;import javax.servlet.http.HttpServletResponse;import javax.servlet.http.HttpSession;import org.springframework.web.servlet.handler.HandlerInterceptorAdapter;public class AuthorInterceptor extends HandlerInterceptorAdapter { @Override public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception { HttpSession session = request.getSession(true); if(session.getAttribute("user") == null){ response.sendRedirect(request.getContextPath() + "/login"); return false; } return true; }}
在spring-serlvet.xml中添加:
<!-- 拦截器 --> <mvc:interceptors> <mvc:interceptor>
<!--访问的路径在/person后的进行拦截--> <mvc:mapping path="/person/**" /> <bean class="com.iflysse.bbs.interceptor.AuthorInterceptor" /> </mvc:interceptor> </mvc:interceptors>
阅读全文
0 0
- 6、spring拦截器
- spring拦截器.学习.
- spring拦截器配置
- Spring 拦截器
- spring 拦截器例子
- Spring拦截器
- Spring MVC 拦截器
- Spring MVC 拦截器
- Spring MVC 拦截器
- spring MVC拦截器
- spring 拦截器例子
- Spring aop拦截器
- Spring MVC拦截器
- spring mvc 拦截器
- Spring动态拦截器
- spring mvc 拦截器
- spring拦截器配置
- spring mvc 拦截器
- 3、Hibernate一对一、一对多、多对多对应关系
- 4、Hibernate查询语句
- 5、springMVC的校验和数据回显
- 13、TCP数据报结构以及三次握手(图解)
- Django 博客开发教程 12
- 6、spring拦截器
- 1、linu出现切换用户变成bash
- 2、sudo时候出现no valid sudoers sources found, quitting
- webpack+babel+es6+react环境搭建
- 1、linux上离线安装jdk
- 2、linux上离线安装python
- 13、elasticsearch的集群安装
- python的字符串问题
- 1、mysql创建用户和授权总结