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. php私有组件以及创建自己的composer私有组件(packagist+git+composer)

    1.私有组件 大多数时候我们使用的都是公开可用的开源组件,但有时候如果公司使用内部开发的PHP组件,而基于许可证和安全方面的问题不能将其开源,就需要使用私有组件.对Composer而言,这是小菜一碟. ...

  2. centos7搭建zabbix

    参考:https://blog.csdn.net/xiaocong66666/article/details/82818893 安装所需的依赖包即可: yum install gcc gcc-c++ ...

  3. [CF859C] Pie Rules - dp,博弈论

    有一个长度为n的序列,Alice和Bob在玩游戏.Bob先手掌握决策权. 他们从左向右扫整个序列,在任意时刻,拥有决策权的人有如下两个选择: 将当前的数加到自己的得分中,并将决策权给对方,对方将获得下 ...

  4. Initialization of bean failed; nested exception is java.lang.NoClassDefFoundError: org/objectweb/asm/Type

    问题描述 将项目挂载到 Myeclipse 的 tomcat 上,启动 tomcat ,报错“Initialization of bean failed; nested exception is ja ...

  5. Java大全-吐血整理

    gqzdev

  6. python3练习100题——037

    原题链接:http://www.runoob.com/python/python-exercise-example37.html 题目:对10个数进行排序. 程序分析:可以利用选择法,即从后9个比较过 ...

  7. 修改json数据中key(键值)

    //方法一:修改JSONObject的键 public static JSONObject changeJsonObj(JSONObject jsonObj,Map<String, String ...

  8. jQuery---入口函数的写法

    入口函数的写法 <!DOCTYPE html> <html lang="zh-CN"> <head> <meta charset=&quo ...

  9. C3P0连接技术

    1.导入jar包(两个) c3p0-0.9.5.2.jar和mchange-commons-java-0.2.12.jar导入数据库驱动jar包 2.定义配置文件 配置文件名称:c3p0.proper ...

  10. url跳转问题

    window.history.replaceState(null, null, "/callPlanning/1") //替换路径不刷新页面 window.location.rep ...