Struts2入门
来源:互联网 发布:网络主播工资 编辑:程序博客网 时间:2024/05/24 00:26
Struts2入门初步需掌握
1.struts2 概述
2.struts2 环境搭建 ( 第一个 struts2 的应用程序 )
3.struts.xml 文件配置详解
4.struts2 请求的 URL 的搜索路径的顺序概述
5.struts2 工作原理概述
6.struts2 指定多个配置文件
7.struts2 动态方法调用
8. 使用通配符定义 action
一:简介
Struts 2 是 Struts 的下一代产品,是在 struts 1 和 WebWork 的技术基础上进行了合并的全新的 Struts 2 框架。其全新的 Struts 2 的 体系结构 与 Struts 1 的体系结构差别巨大。 Struts 2以 WebWork 为 核心 ,采用拦截器的机制来处理用户的请求,这样的设计也使得业务逻辑控制器能够与 Servlet API 完全脱离开,所以 Struts 2 可以理解为 WebWork 的更新产品。虽然从 Struts 1 到Struts 2 有着太大的 变化 ,但是相对于 WebWork , Struts 2 的变化很小。
二:环境搭建
搭建 Struts2 环境时,我们一般需要做以下几个步骤的工作:
1.找到开发Struts2应用需要使用到的jar文件 .
下载官网:
http://struts.apache.org/download.cgi#struts221
解压后:
开始学习使用依赖的最基本的 jar 包
2:编写Struts2的配置文件
解压其中一个案例 在此目录下找到 struts.xml 文件先拷贝到项目的 src 下。 再对起进行修改。
3:在web.xml中加入Struts2MVC框架启动配置
将如下代码 拷贝至 web.xml 配置文件中(从下载的案例中粘贴的)
struts2 org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter struts2 /*
三:基本案例:----------HellowWorld
java类在src下
package action; public classHelloAction { private String message; public String getMessage() { return message; } public void setMessage(Stringmessage) { this.message = message; } public String execute(){ this.message="我的第一个 struts程序"; return "success"; } public String other(){ this.message="第二个方法"; return "success"; } }
配置struts2 文件------Struts.xml代码:
/WEB-INF/pages/index.jsp
运行结果
四:注意:
默认值
如果没有为action指定class,默认是ActionSupport。
2>如果没有为action指定method,默认执行action中的execute() 方法。
3>如果没有指定result的name属性,默认值为success。
http:localhost:端口/内容路径/包名/action名称!方法名
动态方法调用:
大家可以发现在上面的java类中还有一个方法------other()
调用方式如下:
提示,这种调用方式会带来安全隐患!
使用最新 struts2(2.3.15.2) ,不能使用 DMI 动态调用方法
通配符使用:
将 struts.xml 文件的 action 修改
访问方式为 包名 + 命名空间 +test_+ 方法名
原文:http://www.2cto.com/kf/201403/282979.html
- Struts2入门
- struts2 入门
- struts2入门
- struts2-入门
- struts2入门
- struts2入门
- Struts2入门
- struts2入门
- Struts2入门
- struts2 入门
- struts2-入门
- Struts2入门
- struts2 入门
- struts2入门
- Struts2入门
- struts2入门
- Struts2入门
- Struts2入门
- spi模式sd卡的linux设备驱动移植
- 进程管理
- MATLAB: try-catch-end用法
- 利用快慢速算法查找单链表中间节点
- LintCode : 跳跃游戏
- Struts2入门
- 微信JS接口
- Activiti 流程中得到 MultiInstanceLoopCharacteristics参数
- 非阻塞算法(Non-blocking Algorithm)
- 性能优化之电量优化2-使用Battery Historian生成电量消耗报告
- 图toposort
- java hashcode作用
- 复习Core Graphics-2
- 最小二乘法多项式曲线拟合原理与实现