环境搭建:
1.1 jar
1.2 web.xml
1.3 struts.xml
struts.xml(核心配置文件)
<dependency>
<groupId>org.apache.struts</groupId>
<artifactId>struts2-core</artifactId>
<version>2.5.13</version>
</dependency>
User:
helloaction:
struts-sy-xml
将struts-sy-xml配置好以后就可以运行,图中的<action name="/hello_*" class="com.web.helloaction" method="{1}">中的*高代表着调用第一个方法也就是由后面的method所设置
初步的运行结果
2.3 与J2EE容器交互
2.3.1 非注入
2.3.1.2 耦合
ServletActionContext
2.3.1.2 解耦(建立使用解耦模式)
ActionContext
2.3.2 注入
2.3.2.1 耦合
作业:找出struts2中其它的几个注入接口(XxxAware)
2.3.2.2 解耦
在helloaction页面实现以下接口
定义request属性,利用this.request.setAttribute("rs", User1);将值传到前台,以达到传值的目的
前台代码:
结果: