SSM 框架拦截器:实现用户验证
来源:互联网 发布:不是我不爱你网络歌手 编辑:程序博客网 时间:2024/06/14 12:38
这里写一个 SSM 框架拦截器实现用户验证的例子
废话不多说,直接看代码。首先,配置拦截器,springMVC.xml如下:
<?xml version="1.0" encoding="UTF-8"?><beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:aop="http://www.springframework.org/schema/aop" xmlns:p="http://www.springframework.org/schema/p" xmlns:mvc="http://www.springframework.org/schema/mvc" xmlns:context="http://www.springframework.org/schema/context" xmlns:tx="http://www.springframework.org/schema/tx" xsi:schemaLocation="http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-3.0.xsd http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc-4.0.xsd http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-3.0.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-4.0.xsd"> <!-- 配置用注解的方式实现处理器 --> <context:component-scan base-package="com.user.*"></context:component-scan> <!-- 配置视图解析器 --> <bean class="org.springframework.web.servlet.view.InternalResourceViewResolver"></bean> <!-- 配置拦截器 --> <mvc:interceptors> <mvc:interceptor> <mvc:mapping path="/**"/> <bean class="com.movesys.interceptor.TimeInterceptor"></bean> </mvc:interceptor> </mvc:interceptors></beans>
拦截器代码LoginInterceptor.java如下:
package com.user.interceptor;import javax.servlet.http.HttpServletRequest;import javax.servlet.http.HttpServletResponse;import javax.servlet.http.HttpSession;import org.springframework.web.servlet.HandlerInterceptor;import org.springframework.web.servlet.ModelAndView;import com.user.bean.User;/** * 登陆验证 * @author LIU * @version 1.0 2017-10-31 */public class LoginInterceptor implements HandlerInterceptor { @Override public void afterCompletion(HttpServletRequest arg0, HttpServletResponse arg1, Object arg2, Exception arg3) throws Exception { // TODO Auto-generated method stub } @Override public void postHandle(HttpServletRequest arg0, HttpServletResponse arg1, Object arg2, ModelAndView arg3) throws Exception { // TODO Auto-generated method stub } /** * Handler执行之前调用这个方法 */ @Override public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object arg2) throws Exception { // TODO Auto-generated method stub //获取请求的URL String url = request.getRequestURI(); //URL:login.jsp是公开的;这个demo是除了login.jsp是可以公开访问的,其它的URL都进行拦截控制 if(url.indexOf("login.action")>=0){ return true; } //获取Session HttpSession session = request.getSession(); User currUser = (User)session.getAttribute("currUser"); if(currUser != null){ return true; } //不符合条件的,跳转到登录界面 request.getRequestDispatcher("login.jsp").forward(request, response); return false; }}
阅读全文
0 0
- SSM 框架拦截器:实现用户验证
- (转) ssm 拦截器验证用户登录session
- ssm框架之拦截器
- Apache CXF拦截器Interceptor实现WebServices用户验证
- Apache CXF拦截器Interceptor实现WebServices用户验证
- 基于SSH2框架Struts2拦截器的登录验证实现
- 基于SSH2框架Struts2拦截器的登录验证实现
- 基于SSH2框架Struts2拦截器的登录验证实现
- 基于SSH2框架Struts2拦截器的登录验证实现
- 基于SSH2框架Struts2拦截器的登录验证实现
- 拦截器验证用户是否登录
- 拦截器实现用户权限验证
- ssm框架后台对app的接口进行登录验证(拦截器,更智能只要方法上面有这个定义注解就验证)
- Struts2拦截器—自定义拦截器验证用户登录
- SSM-拦截器
- ssm配置拦截器
- 自定义拦截器(SSM)
- ssm:拦截器
- PhalApi-Excel
- No CMAKE_C_COMPILER could be found.
- Java集合
- webuploader按钮不起作用终极解决
- SDP协议详细总结
- SSM 框架拦截器:实现用户验证
- unity官方内置网络unet的实例教程(四)
- 悉尼峰会:OpenStack进入发展新阶段 开放战略迎来累累硕果
- 悉尼峰会:部署 BareMetal 云不是一件容易的事,但我们做到了!
- 悉尼峰会: OpenStack 与 Kubernetes 融合之路
- Go语言实现拓扑排序
- flask结构化目录后如何运行manage
- 5.10告诉年限和月份得出该月份天数
- 委托深入理解