首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 软件管理 > 软件架构设计 >

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

2012-11-07 
Struts2.x快速上手4--对视图的改进(使用struts标签库)目的:尽可能的消灭jsp中的Java代码1)加入标签库:%@

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/>

热点排行