struts2入门

环境搭建:
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);将值传到前台,以达到传值的目的

前台代码:

 

结果:

 

转载于:https://www.cnblogs.com/xhpcc/p/11251193.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值