struts2 入门
来源:互联网 发布:软件的三层架构 编辑:程序博客网 时间:2024/06/07 03:30
a、普通java类 实现 execute 方法
b、类实现 Action 接口
c、继承 ActionSupport 类
2、 action中的方法的调用
a、 直接调用 execute
b、通过 method 属性配置要调用的 Action 中的方法 ,通配符 匹配 方法名
c、DMI : struts.xml的配置中打开动态调用, action名为: Action!方法名
2.1、链接是跳至同一个 action ,但是需要不同的操作
a、通配符解决
在action类中 实现多个方法 如 add() delete()
配置struts.xml 的action :name="*_person" calss="" method="{1}"
若 action为 add_person ,add匹配上 自己写的actionlei中的 add() 方法名,
就可以直接调用 add 方法实现链接地址相同而操作不同的执行方式
b、DMI 动态方法调用 涉及安全性问题,不推荐
2.2、默认的action的配置:当请求的地址不存在或者没有和当前已有的action匹配成功时,跳转到默认的action
<default-action-ref name="index" />
<!-- 配置默认的action,当然需要这个action 是存在的 -->
<action name="index">
<result>
/index.jsp
</result>
</action>
3、struts2 传递参数: a、简单类型: 表单传参,
b、对象类型
c《推荐》、modelDriven 传递复杂类型数据
4、访问 web 对象
a、通过ActionContext.getContext 得到一个ActionContext对象
request=(Map<String, Object>) ActionContext.getContext().get("request");
session= ActionContext.getContext().getSession();
application=ActionContext.getContext().getApplication();
b 《推荐》、通过接口,由struts2 注入, map 是struts2 转换了 j2ee对象 底层的回调机制
实现 XXXAction implements RequestAware SessionAware ApplicationAware
c、通过 ServletActionContext.getRequest() 得到一个 HttpServletRequest对象 ,再根据request取到其他的web 对象
d、通过实现 ServletRequestAware 接口,注入 HttpServletRequest 对象,根据request取到其他的web 对象
4访问web对象总结:通过接口的实现是 IOC 控制反转方式: inversion of control
- Struts2入门
- struts2 入门
- struts2入门
- struts2-入门
- struts2入门
- struts2入门
- Struts2入门
- struts2入门
- Struts2入门
- struts2 入门
- struts2-入门
- Struts2入门
- struts2 入门
- struts2入门
- Struts2入门
- struts2入门
- Struts2入门
- Struts2入门
- Java实用I/O方法总结
- 解决 Error occurred during initialization of VM java/lang/NoClassDefFoundError: java/lang/O...
- BT种子文件信息库-TorrentinfoLibrary
- java设计模式学习之观察者模式(一)
- Linux 内核模块makefile
- struts2 入门
- Segments - POJ 3304 线段相交
- 开源ETL工具 Pentaho Kettle
- jdk动态代理(动态生成字节码与反射机制的结合)
- Product of Array Except Self
- 使用pip安装numpy库问题汇总
- 机器学习之径向基神经网络(RBF NN)
- 全排列和全组合实现
- 第三方登录(二)