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文件上传 form表单形式

    1.php界面 <?php header( 'Content-Type:text/html;charset=utf-8 ');include_once("conn/conn.php&q ...

  2. PHP实现微信公众号分享接口

    还是一贯风格:用代码说话!!! <?php class ShareModel extends BaseModel { var $appId = APPID; var $appSecret = A ...

  3. wget安装nginx

    #下载: wget http://nginx.org/download/nginx-1.8.0.tar.gz #解压: tar -zxvf nginx-1.8.0.tar.gz #安装依赖插件 yum ...

  4. python调用HEG工具批量处理MODIS数据

    下面的代码主要用于使用python语言调用NASA官方的MODIS处理工具HEG进行投影坐标转换与重采样批量处理 主要参考 HEG的用户手册:https://newsroom.gsfc.nasa.go ...

  5. Docker的安装和操作(虚拟机+linux系统)

    1.简介 Docker是一个开源的应用容器引擎:是一个轻量级容器技术: Docker支持将软件编译成一个镜像:然后在镜像中各种软件做好配置,将镜像发布出去,其他使用者可以直接使用这个镜像: 运行中的这 ...

  6. webscarab

    1.功能 WebScarab是一个用来分析使用HTTP和HTTPS协议的应用程序框架.其原理很简单,WebScarab可以记录它检测到的会话内容(请求和应答),并允许使用者可以通过多种形式来查看记录. ...

  7. 【SQL】基础概念

    1.. In order to find the rows where the value for a column is or is not NULL, you would use IS NULL  ...

  8. 测试准确率计算方法说明 pre.eq(target).float().sum().item()

    测试准确率计算方法说明 pre.eq(target).float().sum().item() 待办 pred = logits.argmax(dim=1) correct += pred.eq(ta ...

  9. Linux - Shell - 算数表达式 - 位运算

    概述 shell 中基于 $(()) 的 位运算 背景 复习 shell 脚本 凑数吧 准备 环境 os centos7 1. 位运算 代码 #!/bin/bash # 位运算 arg1=2 arg2 ...

  10. Chrome浏览器所有页面崩溃

    问题描述 Chrome浏览器所有页面崩溃,包括设置页面,"喔唷,崩溃啦!" 显示错误码:STATUS_INVALID_IMAGE_HASH Chrome所有插件报错,右下角一串弹框 ...