1.在LoginAction.java中,extends ActionSupport
package com.jsu.struts2.action; import com.opensymphony.xwork2.ActionContext; import com.opensymphony.xwork2.ActionSupport; public class LoginAction extends ActionSupport { @Override public String execute() throws Exception { //判断用户的执行效率 for (int i = 0; i < 1000000; i++) { } System.out.println("OK"); System.out.println(" Action Execute..."); return SUCCESS; } }
2.MyInterceptor.java中extends AbstractInterceptor
package com.jsu.struts2.interceptor; import com.opensymphony.xwork2.ActionInvocation; import com.opensymphony.xwork2.interceptor.AbstractInterceptor; public class MyInterceptor extends AbstractInterceptor { private String test;//测试属性 @Override public String intercept(ActionInvocation invocation) throws Exception { System.out.println("Interceptor Start..."+test); long start = System.currentTimeMillis(); String path=invocation.invoke(); System.out.println("Interceptor end...."); long end = System.currentTimeMillis(); System.out.println("My 1 END 程序执行时长=" + (end - start)); return path; } public String getTest() { return test; } public void setTest(String test) { this.test = test; } }
3.在struts.xml中配置
<struts> <package name="loginDemo" namespace="/" extends="struts-default"> <interceptors> <interceptor name="MyInterceptor" class="com.jsu.struts2.interceptor.MyInterceptor"></interceptor> <!-- 如果有多个拦截器一起调用,配置拦截器栈,拦截器栈也能引用拦截器栈 --> <interceptor-stack name="myStack"> <interceptor-ref name="MyInterceptor"> <param name="test">拦截器的第一个参数</param> </interceptor-ref> </interceptor-stack> </interceptors> <action name="login" class="com.jsu.struts2.action.LoginAction"> <interceptor-ref name="myStack"> <!-- 修改拦截器属性的初始值 --> <param name="MyInterceptor.test">修改后的拦截器第一个参数</param> </interceptor-ref> <interceptor-ref name="defaultStack"></interceptor-ref> <result>/index.jsp</result> </action> </package> </struts>
4.页面发送请求http://localhost:8080/struts2_04/login
发表评论
-
struts2day06 自定义结果
2012-07-16 12:14 683类implements Result接口 或者 extends ... -
struts2day06 Struts2.0的result
2012-07-16 12:01 958Struts2.0的result Action ... -
struts2day06学习笔记
2012-07-16 10:55 8601.new String(xxx.getBytes(),&qu ... -
struts2day05异常处理
2012-07-13 23:13 838Struts2.0的异常处理机制 1.什么是异常?软件在 ... -
Struts2day05学习笔记
2012-07-13 22:19 6851.自定义拦截器 1.im ... -
Struts2day04Struts2.0文件的下载
2012-07-13 08:26 6851.写一个Action,在DownloadAction ext ... -
Struts2day04Struts2.0文件的上传
2012-07-13 08:20 6541、在服务器端提供一个文件夹存放提交的文件,upload文件夹 ... -
Struts2day04Struts2.0实现阻止表单重复提交
2012-07-12 21:01 6481.使用叫做token的拦截器,在表单中加入<s:tok ... -
Struts2day04对Action的方法进行过滤拦截
2012-07-12 20:38 17861.写一个Action类 UserManagerAction ... -
Struts2day04判断用户是否登录
2012-07-12 19:37 8801.在拦截器中获得用户登录的session 在LoginC ... -
Struts2学习笔记day04
2012-07-12 00:31 6221.自定义类型转换 1.写一个类 extends S ... -
Struts2day03Struts2.0提供的数据格式校验
2012-07-11 21:52 722Struts2.0提供的数据格式校验 js校验:存在被 ... -
Struts2day03Struts2.0国际化
2012-07-11 21:09 782Struts2.0国际化 B/S结构中为网页提供多国 ... -
Struts2day03OGNL自定义类型转换
2012-07-11 20:47 818Struts2.0框架不能够或者不能完整的进行自动类型转换 ... -
Struts2学习笔记day03
2012-07-11 19:09 9551.值栈:ValueStack,存储数 ... -
Struts2day02多个对象提交
2012-07-10 07:15 1192在listUser.jsp页面 <%@ page la ... -
Struts2day02表单标签
2012-07-10 07:15 6691.在struts2Form.jsp中 <%@ ... -
struts2day02访问ValueStack中的数据以及访问Context中的对象
2012-07-10 07:14 10511.在show.jsp页面 <%@ page lang ... -
Struts2day02动态方法调用
2012-07-10 07:14 6581.在opt.jsp页面 <%@ page langu ... -
Struts2day02使用通配符调用指定的方法
2012-07-10 07:14 7341.在opt.jsp页面 <%@ page langu ...
相关推荐
标题中的“传智168期JavaEE struts2杜宏 day 29~day31笔记”暗示了文档是一系列关于JavaEE技术栈中的Struts2框架的课程笔记,由杜宏教授,并且特别强调了是从29天到31天的学习内容。JavaEE(Java Platform, ...
6. **Value Stack**:Struts2中的数据容器,用于存储Action的属性和Ognl表达式中的对象。 在"struts2_day1"这个压缩包中,我们可能看到的文件结构如下: - `struts2_day1/`: 项目根目录 - `src/main/java/`: 包含...
在提供的压缩包文件中,"struts_day_01.pdf"可能涵盖了Struts的基本概念和安装配置,"struts_day_02[3].pdf"可能涉及了标签库的使用,"struts_day_05.pdf"可能讲解了验证框架的详细操作,而"struts_day_06.pdf"可能...
在Struts2中,视图通常由JSP页面来实现。可以通过`<s:property>`标签来显示Action中的属性值。 示例JSP页面: ```jsp ; charset=UTF-8" pageEncoding="UTF-8"%> <!DOCTYPE html> <title>Hello World Example ...
4. **参数绑定**:Struts2支持模型驱动,可以自动将表单数据绑定到Action类的属性,如`username`和`password`,这样在`execute`方法中可以直接访问这些值。 5. **验证逻辑**:在`execute`方法中,需要对用户输入的...