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 过滤器】的更多相关文章

  1. struts2和servlet同时用(访问servlet时被struts2过滤器拦截问题的解决)

    在同一个项目中间,如果既用到servlet有用了struts2的框架,运行项目时可能无法正常使用servlet,原因是在配置struts2的核心控制器时<url-pattern>/*< ...

  2. Struts2 过滤器与拦截器

    学习Struts2时,发现有过滤器和拦截器,他们貌似都是一样的功能,但是为什么会有2个不同的名称呢?肯定是有区别的,所以打算自己整理一下. 过滤器,是在java web中,你传入的request,re ...

  3. struts2 过滤器和拦截器的区别和使用

    java web 过滤器和拦截器的区别和使用  1.1 什么是拦截器:      拦截器,在AOP(Aspect-Oriented Programming)中用于在某个方法或字段被访问之前,进行拦截然 ...

  4. struts2 过滤器

    Chain.doFilter的作用就是继续请求的传递,可传递给下一个filter也可传递给目标页面 如左侧传递给filter2,但fiter2使用上面或者下面的方法将倾情重定向到一个新的页面,而不再传 ...

  5. struts2 核心过滤器的配置

    <!-- struts2 过滤器核心配置--> <filter> <filter-name>struts2</filter-name> <filt ...

  6. 深入Struts2的过滤器FilterDispatcher--中文乱码及字符编码过滤器

    引用 前几天在论坛上看到一篇帖子,是关于Struts2.0中文乱码的,楼主采用的是spring的字符编码过滤器(CharacterEncodingFilter)统一编码为GBK,前台提交表单数据到Ac ...

  7. Struts2中文乱码问题 过滤器源码分析

    整理自网上: 前几天在论坛上看到一篇帖子,是关于Struts2.0中文乱码的,楼主采用的是spring的字符编码过滤器 (CharacterEncodingFilter)统一编码为GBK,前台提交表单 ...

  8. SSH(Struts2+Spring+Hibernate)框架搭建流程

    添加支持 我先介绍的是MyEclipse9的自带框架支持搭建过程:(完全的步骤 傻瓜式的学习..~) 首先我们来搭建一个Web项目: 一.Hibernate(数据层)的搭建: 相关描述 Ⅰ.服务器与数 ...

  9. struts2学习笔记--OGNL表达式1

    struts2标签库主要使用的是OGNL语言,类似于El表达式,但是强大得多,它是一种操作对象属性的表达式语言,OGNL有自己的优点: 能够访问对象的方法,如list.size(); 能够访问静态属性 ...

随机推荐

  1. VMware vSphere Client

    复制虚拟机 在虚拟机关机状态下,选中一个虚拟机,文件 - 导出 - 导出OVF模板,导出成功后,再文件 - 部署OVF模板(修改IP.MAC.主机名称)

  2. 【做题笔记】洛谷P1506 拯救oibh总部

    跑一遍染色法,最后判断哪些位置没被染色即可 一些技巧: 为了判断方便,把字符转换成 int 型的数字. 注意边界问题 详细解释见代码 #include <iostream> #includ ...

  3. 重新认识urllib

    # coding=utf-8 # urllib_get_file=urllib.request.urlretrieve(url=None,filename="test.zip") ...

  4. Python里的Flask开发环境的搭建

    在已经安装好了Python后,我这里用的是Python3.5,准备进一步学习Flask框架,下面记录搭建Flask环境 这里使用了虚拟环境,在虚拟环境里,最小化的安装Flask. 参考步骤: 1.首先 ...

  5. ApiBehaviorOptions 统一模型验证配置不生效

    ApiBehaviorOptions 的统一模型验证配置一定要放到(.AddMvc)后面.

  6. 创建spring boot 项目

    1.新建Spring Starter Project(需要连接外网) 2.选择web 3.点击完成,生成maven项目 pom文件默认有一些依赖,但是有一个地方报错,<parent>节点报 ...

  7. 关于微信小程序

    1.设置了tabBar的页面,好像用navigator跳不过去.

  8. resample matlab实现

    使用线性插值实现sample rate转换. function output = simpleResample(input, inputfs, outputfs) inputLen = length( ...

  9. Big research problems (1)

    1. how to measure the uncertainty of prediction model or data analysis? 2.

  10. C++-怎样写程序(面向对象)

    使用编程语言写好程序是有技巧的. 主要编程技术: 1. 编程风格 2. 算法 3. 数据结构 4. 设计模式 5. 开发方法 编程风格指的是编程的细节,比如变量名的选择方法.函数的写法等. 算法是解决 ...