<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>struts2的一个例子</title>
</head>
<body>
<a href="${pageContext.request.contextPath }/hello">hello</a><br/> </body>
</html>

index.jsp代码

 package com.xiaostudy.web;

 import com.opensymphony.xwork2.ActionSupport;

 public class Hello extends ActionSupport {

     public String print() {
System.out.println("Hello类的print方法执行了。。。。");
return SUCCESS;
}
}

action动作类Hello.java代码

 package com.xiaostudy.web;

 import com.opensymphony.xwork2.ActionInvocation;
import com.opensymphony.xwork2.interceptor.AbstractInterceptor; public class Demo1_Interceptor extends AbstractInterceptor { @Override
public String intercept(ActionInvocation invocation) throws Exception {
System.out.println("Demo1_Interceptor调用之前>>>>>>>");
String str = invocation.invoke();//放行
System.out.println(str);
System.out.println("Demo1_Interceptor调用之后<<<<<<<<");
return str;
} }

自定义拦截器Demo1_Interceptor.java代码

 <?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.devMode" value="true"/> <package name="hello" extends="struts-default">
<interceptors><!-- 自定义拦截器声明 注意:name里面不能有下划线_ -->
<interceptor name="demo1Interptor" class="com.xiaostudy.web.Demo1_Interceptor"></interceptor>
</interceptors>
<action name="hello" class="com.xiaostudy.web.Hello" method="print">
<interceptor-ref name="demo1Interptor"></interceptor-ref><!-- 使用自定义拦截器 -->
<result name="success" >/ok.jsp</result>
<result name="input">/err.jsp</result>
</action>
</package>
</struts>

struts.xml代码

struts2自定义Interceptor拦截器的更多相关文章

  1. 模仿Struts2的Interceptor拦截器实现

    模仿Struts2的Interceptor拦截器实现 public interface Invocation { public Object invoke(); } public interface ...

  2. struts2自定义登录拦截器

    版权声明:本文为博主原创文章,未经博主允许不得转载. (1)配置web.xml,让xml加载struts2框架 <?xml version="1.0" encoding=&q ...

  3. struts2学习笔记--拦截器(Interceptor)和登录权限验证Demo

    理解 Interceptor拦截器类似于我们学过的过滤器,是可以在action执行前后执行的代码.是我们做web开发是经常使用的技术,比如权限控制,日志.我们也可以把多个interceptor连在一起 ...

  4. struts2内置拦截器和自定义拦截器详解(附源码)

    一.Struts2内置拦截器 Struts2中内置类许多的拦截器,它们提供了许多Struts2的核心功能和可选的高级特 性.这些内置的拦截器在struts-default.xml中配置.只有配置了拦截 ...

  5. Java进阶知识02 Struts2下的拦截器(interceptor)和 过滤器(Filter)

    一.拦截器 1.1.首先创建一个拦截器类 package com.bw.bms.interceptor; import com.opensymphony.xwork2.ActionContext; i ...

  6. 5.Struts2中的拦截器

    拦截器是Struts2中的核心,其自带很多很多的拦截器,这里主要介绍一下自定义拦截器,恩多一半情况下呢?我们不需要使用到自定义的拦截器,Struts2本身已经提 供了很多的拦截器供我们使用,对于自定义 ...

  7. Struts2(十四)拦截器实现权限管理

    一.认识拦截器 拦截器也是一个类 拦截器可以在Action被调用之前和之后执行代码 框架很多核心功能是拦截器实现的 拦截器的特点: 拦截器自由组合,增强了灵活性.扩展性.有利于系统解耦 拦截器可以拦截 ...

  8. 十五、struts2中的拦截器(框架功能核心)

    十五.struts2中的拦截器(框架功能核心) 1.过滤器VS拦截器 功能是一回事. 过滤器是Servlet规范中的技术,可以对请求和响应进行过滤. 拦截器是Struts2框架中的技术,实现AOP(面 ...

  9. Struts2笔记_拦截器

    A.拦截器是什么 --- Interceptor:拦截器,起到拦截Action的作用. ---Filter:过滤器,过滤从客户端向服务器发送的请求. ---Interceptor:拦截器,拦截是客户端 ...

随机推荐

  1. 【BZOJ4566】[Haoi2016]找相同字符 后缀数组+单调栈

    [BZOJ4566][Haoi2016]找相同字符 Description 给定两个字符串,求出在两个字符串中各取出一个子串使得这两个子串相同的方案数.两个方案不同当且仅当这两 个子串中有一个位置不同 ...

  2. 第一个Gradle入门程序

    参考:http://www.importnew.com/15881.html 准备工作 1.gradle编译环境 下载gradle编译包(http://www.gradle.org/downloads ...

  3. [LintCode] 第k大元素

    基于快速排序: class Solution { public: /* * param k : description of k * param nums : description of array ...

  4. 将list集合,元素随机打乱

    for循环+随机数 实现相同位置的元素交换 public <T> void shuffle(List<T> list) { int size = list.size(); Ra ...

  5. delphi 遇到问题、报错等

    解决方法:using Windows

  6. Windows如何使用Apache的ab工具进行网站性能测试(Apache服务器自带了ab压力测试工具,可以用来测试网站性能,使用简单方便)

    打开Apache服务器的安装路径,在bin目录中有一个ab.exe的可执行程序,就是我们要介绍的压力测试工具. 在Windows系统的命令行下,进入ab.exe程序所在目录,执行ab.exe程序.注意 ...

  7. 被Chrome下的remove闪了一下腰

    有用户反映说购物车删除不了东西,于是有了下面的测试. 浏览器:ie7 ie8 ie9 chrome 代码: <a href="javascript:" onclick=&qu ...

  8. MFC DLL获取当前路径

    .首先定义此获取模块的静态方法 #if _MSC_VER >= 1300 // for VC 7.0 // from ATL 7.0 sources #ifndef _delayimp_h ex ...

  9. 洛谷P4475 巧克力王国

    洛谷P4475 巧克力王国 题目描述 巧克力王国里的巧克力都是由牛奶和可可做成的. 但是并不是每一块巧克力都受王国人民的欢迎,因为大家都不喜欢过于甜的巧克力. 对于每一块巧克力,我们设 x 和 y 为 ...

  10. Python模块学习之bs4

    1.安装bs4 我用的ubuntu14.4,直接用apt-get命令就行 sudo apt-get install Python-bs4 2.安装解析器 Beautiful Soup支持Python标 ...