也谈jstl

前两天要写个简单的页面,中间要用到jstl标签,遇到了很多问题。今天抽时间上网查了查资料,把这些问题解决一下。
java中代码如下:

put("vo", virtualHostVO);
put("listTheme", listTheme);
put("newGoodsCode",newGoodsCode);


[size=x-large]1.使用JSTL标签来访问list并判断list中的选中项 [/size]
jsp中访问:

<select name="newGoodsCode" onChange="getTheme1();">
<c:forEach var="upgradeProduct" items="${vo.upgradeList}">
<option value="${upgradeProduct.goodsCode}"
<c:if test="${newGoodsCode==upgradeProduct.goodsCode}">selected</c:if>>
${upgradeProduct.goodsName} </option>
</c:forEach>

</select>

简单说明一下:
a.vo的升级线是一个list的产品,将list中的产品遍历在option中。
b. <c:if test="${newGoodsCode==upgradeProduct.goodsCode}">selected</c:if>判断选中的是哪一个升级线上的产品。
[size=x-large]2.获取集合的长度:[/size]
 
<tr>
<c:forEach var="themeVO" items="${listTheme}" varStatus="j" begin="0" end="${fn:length(listTheme)}" >
<c:if test="${j.count%4!=0}">
<td>
<img src="${ctx}/Modules/vzzjz/images/${themeVO.type}/${themeVO.nameEn}/images/theme_view.jpg" width="97" height="113" border="0" alt="${themeVO.nameCh}" />
<br>
<input type = "radio" name = "themeEn" value= "${themeVO.nameEn}"/>${themeVO.nameCh}
</td>
</c:if>
<c:if test="${j.count%4==0}">
<td>
<img
src="${ctx}/Modules/vzzjz/images/${themeVO.type}/${themeVO.nameEn}/images/theme_view.jpg" width="97" height="113" border="0" alt="${themeVO.nameCh}" /><br><input type = "radio" name = "themeEn" value= "${themeVO.nameEn}"/>${themeVO.nameCh}
</td>
</tr>
</c:if>
</c:forEach>
<c:if test="${fn:length(listTheme)%4!=0}">
</tr>
</c:if>

说明:
a.每行显示四条记录:
b.${fn:length(listTheme)}取得集合listTheme的长度
c.<c:forEach var="themeVO" items="${listTheme}" varStatus="j" begin="0" end="${fn:length(listTheme)}" >
遍历集合listTheme,用j来代表当前遍历的个数,用j.count取得数值。
[size=x-large]3.格式化日期型的数据:[/size]

<fmt:formatDate value="${vo.serviceStartDate}" pattern="yyyy-MM-dd"/>

[size=x-large]4.list中是map对象,遍历list[/size]

<c:forEach items="${testList}" var="testMap" varStatus="status">
<td>11111</td>
<c:forEach var="mapItem" items="${testMap}">
<c:if test="${mapItem.key =='name'}">
<td>name:<c:out value="${mapItem.value}"/></td>
</c:if>
<c:if test="${mapItem.key =='age'}">
<td>age:<c:out value="${mapItem.value}"/></td>
</c:if>
</c:forEach>
<td align="right"><c:out value="${liuTest}"/></td>
</tr>
</c:forEach>


[size=x-large]5.以上都是实用中的一些问题,具体的一些基础的说明见下面文档。[/size]
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值