Struts2 (一)
来源:互联网 发布:淘宝怎么清仓 编辑:程序博客网 时间:2024/05/21 20:27
1.配置struts2 过滤器
<filter> <filter-name>Struts2</filter-name> <!-- Struts 2.1.3之后该类就已经被废弃了 替代的类是: org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter --> <filter-class>org.apache.struts2.dispatcher.FilterDispatcher</filter-class> </filter> <filter-mapping> <filter-name>Struts2</filter-name> <url-pattern>/*</url-pattern> </filter-mapping>
2.配置 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> <!--如果需要使用struts2默认xml中特性 就必须继承struts-default namespace定义action上层路径 比如namespace定义为 /test action定义为 login 访问路径为 /test/login.action --> <package name="hellowPakage" namespace="/" extends="struts-default"> <!-- struts2的action定义 name为action的路径 class为对应的处理类 如果不定义method属性 会自动进入execute方法 如果定义了方法调转到定义的方法 --> <action name="login" class="com.etop.struts2.action.StrutsAction" > <result name="success">/suc.jsp</result> </action> <action name="resetFom" class="com.etop.struts2.action.StrutsAction" method="resetForm" > <!-- result用于控制action的跳转 name为action返回的名称 type常用的值 : chain,dispatcher,redirect,redirectAction,stream type 是转发的类型 dispatcher:请求转发, chain 请求转发 跳转action redirect请求重定向 redirectAction 请求重定向到action stream 文件下载 --> <result name="success" type="redirect">/login.jsp</result> </action> </package></struts>
3.编写Action
package com.etop.struts2.action;import com.opensymphony.xwork2.ActionSupport;/** * struts2可以是任意一个pojo类 不需要继承任何对象\ * 如果需要使用struts2的高级特性 就必须继承 ActionSupport * @author teacher * */public class StrutsAction extends ActionSupport{ private String ruserName; private String rpassword; /** * Struts2方法结构 返回值必须是String类型 不需要任何 参数 * 返回参数 决定需要跳转的jsp * 必须在struts.xml定义result * execute是ActionSupport 默认的执行方法 * @return */ public String execute(){ return "success"; } public String resetForm(){ return "success"; } public String getRuserName() { return ruserName; } public void setRuserName(String ruserName) { this.ruserName = ruserName; } public String getRpassword() { return rpassword; } public void setRpassword(String rpassword) { this.rpassword = rpassword; }}
0 0
- struts2 一
- struts2(一)
- Struts2 (一)
- struts2(一)
- Struts2【一】
- struts2(一)
- struts2: 一
- Struts2(一)
- struts2 一
- Struts2:一
- Struts2(一)-Struts2之HelloWorld
- Struts2学习(一) 国际化
- struts2学习笔记(一)
- Struts2 学习笔记一
- Struts2 初识(一)
- Struts2总结 一
- 深入struts2(一)
- struts2.1.8研究(一)
- file.getPath() getAbsolutePath() getCanonicalPath()区别
- 获取系统信息的函数
- 未排序数组中累加和为给定值的最长子数组
- 一些感想
- CC2540 CC2541 CC2530脱机烧录器量产批量生产设备 2路并行烧录
- Struts2 (一)
- C语言的atan()和atan2()函数
- Hadoop Yarn 集群搭建
- Win10+VS2013编译OSG3.4
- struts2 (二)单元测试/通过耦合和非耦合的方式获取和设置值/返回值类型/异常映射
- C#面向对象概念总结
- 携程DynamicAPK插件化框架源码分析
- word2010公式排版、mathtype公式编辑和自动编号
- 记一次ubutnu14.10下安装编译Apache