【 Struts2 过滤器】
LoginInterceptor
package k.util; import com.opensymphony.xwork2.ActionInvocation;
import com.opensymphony.xwork2.interceptor.MethodFilterInterceptor;
import org.apache.struts2.ServletActionContext; import javax.servlet.http.HttpServletRequest; public class LoginInterceptor extends MethodFilterInterceptor {
@Override
protected String doIntercept(ActionInvocation actionInvocation) throws Exception {
HttpServletRequest request = ServletActionContext.getRequest();
Object name = request.getSession().getAttribute("name");
return name == null ? "toLogin" : actionInvocation.invoke();
}
}
struts.xml
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE struts PUBLIC
"-//Apache Software Foundation//DTD Struts Configuration 2.3//EN"
"http://struts.apache.org/dtds/struts-2.3.dtd">
<struts>
<constant name="struts.i18n.encoding" value="UTF-8"></constant>
<package name="struts2-hibernate" extends="struts-default" namespace="/">
<interceptors>
<interceptor name="LoginInterceptor" class="k.util.LoginInterceptor">
<param name="excludeMethods">toLogin,login</param>
</interceptor>
</interceptors>
<action name="student_*" class="k.action.StudentAction" method="{1}">
<interceptor-ref name="LoginInterceptor"></interceptor-ref>
<interceptor-ref name="defaultStack"></interceptor-ref>
<result name="list" type="redirectAction">student_list</result>
<result name="toList">/WEB-INF/student/list.jsp</result>
<result name="toAdd">/WEB-INF/student/add.jsp</result>
<result name="toUpdate">/WEB-INF/student/update.jsp</result>
<result name="toLogin">/WEB-INF/student/login.jsp</result>
</action>
</package>
</struts>
【 Struts2 过滤器】的更多相关文章
- struts2和servlet同时用(访问servlet时被struts2过滤器拦截问题的解决)
在同一个项目中间,如果既用到servlet有用了struts2的框架,运行项目时可能无法正常使用servlet,原因是在配置struts2的核心控制器时<url-pattern>/*< ...
- Struts2 过滤器与拦截器
学习Struts2时,发现有过滤器和拦截器,他们貌似都是一样的功能,但是为什么会有2个不同的名称呢?肯定是有区别的,所以打算自己整理一下. 过滤器,是在java web中,你传入的request,re ...
- struts2 过滤器和拦截器的区别和使用
java web 过滤器和拦截器的区别和使用 1.1 什么是拦截器: 拦截器,在AOP(Aspect-Oriented Programming)中用于在某个方法或字段被访问之前,进行拦截然 ...
- struts2 过滤器
Chain.doFilter的作用就是继续请求的传递,可传递给下一个filter也可传递给目标页面 如左侧传递给filter2,但fiter2使用上面或者下面的方法将倾情重定向到一个新的页面,而不再传 ...
- struts2 核心过滤器的配置
<!-- struts2 过滤器核心配置--> <filter> <filter-name>struts2</filter-name> <filt ...
- 深入Struts2的过滤器FilterDispatcher--中文乱码及字符编码过滤器
引用 前几天在论坛上看到一篇帖子,是关于Struts2.0中文乱码的,楼主采用的是spring的字符编码过滤器(CharacterEncodingFilter)统一编码为GBK,前台提交表单数据到Ac ...
- Struts2中文乱码问题 过滤器源码分析
整理自网上: 前几天在论坛上看到一篇帖子,是关于Struts2.0中文乱码的,楼主采用的是spring的字符编码过滤器 (CharacterEncodingFilter)统一编码为GBK,前台提交表单 ...
- SSH(Struts2+Spring+Hibernate)框架搭建流程
添加支持 我先介绍的是MyEclipse9的自带框架支持搭建过程:(完全的步骤 傻瓜式的学习..~) 首先我们来搭建一个Web项目: 一.Hibernate(数据层)的搭建: 相关描述 Ⅰ.服务器与数 ...
- struts2学习笔记--OGNL表达式1
struts2标签库主要使用的是OGNL语言,类似于El表达式,但是强大得多,它是一种操作对象属性的表达式语言,OGNL有自己的优点: 能够访问对象的方法,如list.size(); 能够访问静态属性 ...
随机推荐
- Centos7安装gitlab-ce
1.官方推荐方式安装 参考https://www.gitlab.com.cn/installation/#centos-7?version=ce sudo yum install -y curl po ...
- TCP/IP详解,卷1:协议--第8章 Traceroute程序
引言 由Van Jacobson编写的Tr a c e r o u t e程序是一个能更深入探索T C P / I P协议的方便可用的工具. 尽管不能保证从源端发往目的端的两份连续的 I P数据报具有 ...
- Joining Data with dplyr in R
目录 inner_join Joining three tables left_join right-join full_join semi- and anti-join Stack Overflow ...
- docker安装elasticsearch和head插件
使用 Docker 拉取ElasticSearch镜像 docker pull elasticsearch:7.0.0 查看镜像 ID docker images 运行 docker run -e E ...
- 巨杉Tech | 使用 SequoiaDB + Docker + Nodejs 搭建 Web 服务器
容器化技术的出现大大简化了应用开发人员在构建底层基础设施的工作.SequoiaDB 巨杉数据库于3.2.1版本正式推出了 Docker 容器化部署方案,本文将会基于 SequoiaDB 巨杉数据库与N ...
- jdk8-》allMatch、anyMatch、max、min函数
allMatch函数: 检查是否匹配所有元素,只有全部符合才返回true boolean flag = list.stream().allMatch(obj->obj.length()>5 ...
- 图的最短路径算法-- Floyd算法
Floyd算法求的是图的任意两点之间的最短距离 下面是Floyd算法的代码实现模板: ; ; // maxv为最大顶点数 int n, m; // n 为顶点数,m为边数 int dis[maxv][ ...
- resample matlab实现
使用线性插值实现sample rate转换. function output = simpleResample(input, inputfs, outputfs) inputLen = length( ...
- Unable to guess the mime type as no guessers are available (Did you enable the php_fileinfo extension?)
原因是没有开启php的php_fileinfo扩展,开启即可. 找到php.ini文件,搜索到php_fileinfo,去掉前面的分号,然后重启服务器apache.nginx下同理. extensio ...
- c++11 lambda简录
本文为转载,详情请观看原文连接 或许,Lambda 表达式算得上是 C++ 11 新增特性中最激动人心的一个.这个全新的特性听起来很深奥,但却是很多其他语言早已提供(比如 C#)或者即将提供(比如 J ...