struts2基础----自定义拦截器
这一章,我们开始struts2中拦截器的学习。
自定义拦截器
一、增加一个自定义的拦截器为类
package com.huhx.interceptor;import com.opensymphony.xwork2.ActionInvocation; import com.opensymphony.xwork2.interceptor.AbstractInterceptor;public class RegisterInterceptor extends AbstractInterceptor {private static final long serialVersionUID = 1L;@Overridepublic String intercept(ActionInvocation invocation) throws Exception {System.out.println("拦截器开始运行....");String resultString = invocation.invoke();System.out.println("拦截器结束运行....");return resultString;} }
二、修改struts.xml配置文件,内容如下:
<?xml version="1.0" encoding="UTF-8" ?> <!DOCTYPE struts PUBLIC"-//Apache Software Foundation//DTD Struts Configuration 2.0//EN""http://struts.apache.org/dtds/struts-2.0.dtd"> <struts><package name="default" namespace="/" extends="struts-default"><interceptors><interceptor name="registerInterceptor" class="com.huhx.interceptor.RegisterInterceptor"></interceptor></interceptors><action name="hello" class="com.huhx.struts.HuhxAction"><result name="success">/huhx.jsp</result><interceptor-ref name="defaultStack"></interceptor-ref><interceptor-ref name="registerInterceptor"></interceptor-ref></action></package> </struts>
三、访问地址:http://localhost:8080/StrutsTest1/hello.action,后台打印地址:
拦截器开始运行.... hello world. 拦截器结束运行....
友情链接
转载于:https://www.cnblogs.com/huhx/p/baseStruts2.html
struts2基础----自定义拦截器相关推荐
- Struts2框架自定义拦截器
Struts2中把某些公共性的功能放置到拦截器中,一般一个拦截器只负责一个功能. 拦截器的与过滤器有很多的相似之处,其中过滤器依赖于servlet容器,拦截器基于反射,不依赖servlet容器, 过滤 ...
- Struts2第七篇【介绍拦截器、自定义拦截器、执行流程、应用】
什么是拦截器 拦截器Interceptor-..拦截器是Struts的概念,它与过滤器是类似的-可以近似于看作是过滤器 为什么我们要使用拦截器 前面在介绍Struts的时候已经讲解过了,Struts为 ...
- Struts2自定义类型转换器、自定义拦截器和用户输入数据的验证
一.自定义类型转换器 1.编写一个类,继承com.opensymphony.xwork2.conversion.impl.DefaultTypeConverter 2.覆盖掉其中的public Obj ...
- Struts2 自定义拦截器(方法拦截器)
转自:http://05061107cm.iteye.com/blog/365504 struts2系统自带了很多拦截器,有时需要我们自己定义,一般有两种方式: 一.实现Interceptor接口 J ...
- 从struts2拦截器到自定义拦截器
http://www.cnblogs.com/withyou/p/3170440.html 拦截器可谓struts2的核心了,最基本的bean的注入就是通过默认的拦截器实现的,一般在struts2.x ...
- Struts2内置拦截器和自定义拦截器
内置拦截器 Struts2中内置类许多的拦截器,它们提供了许多Struts2的核心功能和可选的高级特性.这些内置的拦截器在struts-default.xml中配置.只有配置了拦截器,拦截器才可以正常 ...
- Struts2 自定义拦截器(easy example)
要自定义拦截器需要实现com.opensymphony.xwork2.interceptor.Interceptor接口: 新建一个MyIntercept package com.action;imp ...
- struts2自定义拦截器一——模拟登陆权限验证
1.http://localhost:8083/struts2/user.jsp 表示用户已登陆,存放session对象 2.http://localhost:8083/struts2/quit.js ...
- 在struts2中配置自定义拦截器放行多个方法
源码: 自定义的拦截器类: //自定义拦截器类:LoginInterceptor ; package com.java.action.interceptor; import javax.servlet ...
最新文章
- LeetCode简单题之找出两数组的不同
- [codeforces] 527A Playing with Paper
- Centos 6.5下的OPENJDK卸载和SUN的JDK安装、环境变量配置
- 全国计算机等级考试题库二级C操作题100套(第33套)
- 漂亮特殊字体可复制_12个创意字体免费下载网站
- python文本筛选html_python 正则表达式过滤文本中的html标签 源代码解析
- 转:关掉Archlinux中烦人的响铃
- Redis学习---(14)Redis 事务
- oracle数据库插入多表,在Oracle数据库中插入嵌套表
- 函数 strncpy、strncat、strncmp、strrchr 的实现
- 采集上市公司信息的10个经典方法
- 偷窥Play Framework 2.0
- vscode写的html网页中文乱码
- 记账APP华而不实?Excel门槛太高?不如用它在线记账!
- 使用FFmpeg将文件转为ts
- 使用IDEA写程序时,运行忽然报错,提示:在类*** 中找不到 main 方法, 请将 main 方法定义为: public static void main(String[] args)
- SQLyog Ultimate软件安装教程
- 吹牛前请看这篇:“智能”物流 VS “智慧”物流
- android 打 aab包本地测试注意事项
- PMP笔记-产品核实、范围核实及质量控制的区别
热门文章
- 现在ui设计出来好找工作吗?
- 计算机 学校教一半 自学一半,一半初中生无缘普高,上职业学校怎么样?
- php目录遍历漏洞复现,nginx解析漏洞,配置不当,目录遍历漏洞环境搭建、漏洞复现...
- PHP7 pecl 安装 mongodb扩展 和 PHPLIB
- 接口规范 8. 播出认证相关接口
- linux指令诀窍大全,六个优雅的Linux命令行技巧
- Focal Loss 分类问题 pytorch实现代码(续3)
- 安卓9 webview打开指定url报错或者空白
- resnet,inception,densenet,senet
- 召回率(Recall),精确率(Precision),交除并(Intersection-over-Union(IoU)