拦截器对session验证的实现
来源:互联网 发布:小超市收款软件 编辑:程序博客网 时间:2024/06/07 08:35
自定义一个拦截器
package com.Hanb.fly.interceptor;import java.util.Map;import com.Hanb.fly.model.User;import com.opensymphony.xwork2.Action;import com.opensymphony.xwork2.ActionInvocation;import com.opensymphony.xwork2.interceptor.Interceptor;public class AuthorInterceptor implements Interceptor {@Overridepublic void destroy() {// TODO Auto-generated method stub}@Overridepublic void init() {// TODO Auto-generated method stub}@Overridepublic String intercept(ActionInvocation actionInvocation) throws Exception {// TODO Auto-generated method stubMap session=actionInvocation.getInvocationContext().getSession();User user=(User)session.get("user");if(user==null){System.out.println("拦截器起作用1");return Action.INPUT;}else{System.out.println("拦截器起作用2"); return actionInvocation.invoke();}}}
在struts中配置拦截器
<?xml version="1.0" encoding="UTF-8" ?><!DOCTYPE struts PUBLIC "-//Apache Software Foundation//DTD Struts Configuration 2.0//EN" "http://struts.apache.org/dtds/struts-2.0.dtd"><struts><package name="inter" extends="struts-default"><interceptors> <interceptor name="authenticationInterceptor" class="com.Hanb.fly.interceptor.AuthorInterceptor" /> <interceptor-stack name="myStack"> <interceptor-ref name="authenticationInterceptor" /> <interceptor-ref name="defaultStack" /> </interceptor-stack> </interceptors> <action name="login" class="com.Hanb.fly.action.LoginAction" method="check"> <result>/index1.jsp</result> <result name="input">/index2.jsp</result></action> <action name="show" class="com.Hanb.fly.action.LoginAction" method="show"> <result>/index1.jsp</result> <result name="input">/error.jsp</result> <interceptor-ref name="myStack"></interceptor-ref></action> </package></struts>index.jsp为登录页面,登录成功,在session中设置user,并跳转到index1.jsp
若失败,跳转到index2.jsp。
当请求show.action时,若session中没有设置user,即没有登录,拦截器将返回input,页面跳转入error.jsp。若session中设置user了,拦截器将请求放给show.action。
- 拦截器对session验证的实现
- 拦截器实现对用户是否登录及登陆超时的验证
- SpringMVC拦截器实现登陆时的验证拦截
- 使用struts2拦截器,对session失效的校验
- 使用struts2拦截器,对session失效的校验
- 关于拦截器和过滤器以及实现国际化和session超时验证
- 拦截器实现用户权限验证
- shiro 拦截器实现session过期拦截ajax请求的处理
- struts2 使用拦截器 实现用户权限的验证
- 基于SSH2框架Struts2拦截器的登录验证实现
- 基于SSH2框架Struts2拦截器的登录验证实现
- 基于SSH2框架Struts2拦截器的登录验证实现
- Struts2的拦截器特性实现登录验证
- 基于SSH2框架Struts2拦截器的登录验证实现
- 基于SSH2框架Struts2拦截器的登录验证实现
- SpringMVC拦截器实现登录验证的例子
- node.js学习笔记(3)-node.js结合mysql数据库实现的web项目中常见功能--登录验证、session传值、拦截器、ajax传值等
- 实现session验证的lservlet验证码
- Linux学习笔记(三)
- android开发 音乐,文件下载
- 一些不常用的CSS
- git 忽略文件和目录
- PHP实现人人OAuth登录和API调用
- 拦截器对session验证的实现
- PHP+新浪微博开放平台+新浪云平台(SAE)开发微博应用基础
- C++中使用Vector
- PHP+新浪微博开放平台+新浪云平台(SAE)开发微博应用——建立微博应用的过程
- My important experience---android position
- linux学习
- 在Win2008 R2下用 Bonobo Git Server 搭建 Git 服务器
- ZOJ 1014 Operand
- poj 1511----spfa