首先说明我是根据struts-2.3.37版本来学习的,之后的2.5版本我以后会做补充
- 框架:是一个半成品,完成了一部分代码,可以在其基础上再次开发
- struts2框架:是web层使用的mvc框架
- struts2核心:struts核心和xwork核心
- struts2入门
1. 导入jar包

2 . struts.xml位于src下(clasess)
3 . struts.xml文件中的标签
<package>用于管理action
name:包名,唯一
namespace:与action的name属性确定访问action的路径 默认值为空
extends:继承的包名 一般是struts-default
abstact:值为true/false,代表是否可以被继承
<action>声明一个action
name:名称,同一包下不能重名
class:action类全路径,默认值为:ActionSupport
method:action中的方法 返回String 默认值:execute()方法
<result>结果视图
name:与action中的method中的返回值匹配跳转
type:跳转方式 在struts-default.xml中定义
chain:请求转发,跳到另一个action
dispatcher:请求转发,跳到一个jsp页面
redirect:重定向 ,跳到一个jsp页面
redirectAction:重定向 ,跳到一个action
stream:用于下载
5 . struts2框架加载配置文件顺序
1 . default.properties --加载struts2框架中用到的常量
2.struts-default.xml (bean,interceptor,结果类型) struts-plugin.xml (插件) struts.xml
3. struts.properties(自定义常量,一般不用)
4 . web.xml
6 . 定义常量
1 . struts.xml
2 .struts.properties
3 . web.xml
7 . action 的创建方式
1 . POJO类(普通Java类)
2 . implements Action
3 .extends ActionSupport
8 . struts中的 action方法的访问方式
1 . method=xxx
2 . 通配符
3 .动态方法调用
9 . 关于在struts2中获取Servlet API
1 .ActionContext
ActionContext context = ActionContext.getContext();
2 .使用注入
3 . ServletActionContext

本文详细介绍了Struts2框架的基本概念、配置流程及核心组件。包括struts.xml配置、包管理、action声明、结果视图类型及框架加载配置文件顺序等关键信息。
894

被折叠的 条评论
为什么被折叠?



