【 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(); 能够访问静态属性 ...
随机推荐
- 数据库SQL练习(一):数据查询
先创建以下3张基本表 1.学生信息表(Student): 2.课程表(Course): 3.成绩表(Score): 4. 将下列数据输入各个表中 建表SQL: CREATE DATABASE Stud ...
- yii2表单提交CSRF验证
Yii2表单提交默认需要验证CSRF,如果CSRF验证不通过,则表单提交失败,解决方法如下: 第一种解决办法是关闭Csrf public $enableCsrfValidation = false; ...
- Python复制指定目录的各个子目录下的同名文件到指定文件夹并重命名
Python复制指定目录的各个子目录下的同名文件到指定文件夹并重命名 #编码类型 #-*- coding: UTF-8 -*- #导入包 import os import shutil srcpath ...
- 使用 C++11 编写可复用多线程任务池
类的功能 Task (任务基类) 该类主要实现一个任务类 virtual int doWork() = 0; TaskQueue (任务队列) 该类主要针对任务的存储.删除.撤回等状态做管理 Thre ...
- spring 切点表达式
spring切点表达式: 1.*通配符:该通配符主要用于匹配单个单词. 例如:execution(* com.bonnie.Controller.TestController.*()) 上述表达式表示 ...
- [P4549] 【模板】裴蜀定理 - GCD
__gcd真好用 #include <bits/stdc++.h> using namespace std; int main() { int n,x,a=0; cin>>n; ...
- Paper: ModelarDB
Problem: how to store and querry massive amounts of high quality sensor data ingested in real-time f ...
- js处理json字符串
后台输出的字符串为 res= {"result":"true","data":"提交成功"} 前台js无法转化成对象,需 ...
- python logging 总结
基本用法: import sys # 获取logger实例,如果参数为空则返回root logger logger = logging.getLogger("AppName" ...
- BeautifulReport报告
Project description BeautifulReport 一个基于unittest.TestResult模块实现的测试用例模板, 可把测试中的结果通过BeautifulReport整合成 ...