Struts2.x快速上手4--对视图的改进(使用struts标签库)

目的:尽可能的消灭jsp中的Java代码


1)加入标签库:
<%@ taglib prefix="s" uri="/struts-tags"%>

 

2)logon.jsp---->logonPage.jsp
<table border=1>
 <s:form action="Logon" method="post">
  <tr>
   <s:textfield name="username" label="username"></s:textfield>
  </tr>
  <tr>
   <s:password name="password" label="password"></s:password>
  </tr>
  <tr>
   <s:submit value="login"></s:submit>
  </tr>
 </s:form>
</table>

注解:
<s:form/>标签
<s:textfield/>
<s:password/>
<s:submit/>

 

3)viewCompanies.jsp----->listCompanies.jsp
<h1>It公司信息列表</h1>
<table border=1>
 <tr>
  <th>公司名</th>
  <th>城市</th>
  <th>地址</th>
  <th>邮箱</th>
 </tr>
 <!-- 迭代输出ValueStack对象中的comps, 其中status为迭代索引 -->
 <s:iterator value="comps" status="index">
  <!-- 判断索引是否为奇数 -->
  <s:if test="#index.odd == true">
   <tr style="background-color:yellow">
  </s:if>
  <s:else>
   <tr style="background-color:red">
  </s:else>
   <td><s:property value="compName"/></td>
   <td><s:property value="city"/></td>
   <td><s:property value="address"/></td>
   <td><s:property value="email"/></td>
  </tr>
 </s:iterator>
</table>

注解:
<s:if test/>:判断标签
<s:else/>

<s:iterator/>迭代输出,等价于jstl中的<c:forEach/>

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值