JSTL替换Struts标签举例-struts完全手册-hxzon

JSTL替换Struts标签举例-struts完全手册-hxzon

JSTL Replacement Examples

The following sections provide examples for replacing Struts tag library tags with their JSTL equivalents. Remember that not all the Bean, HTML, and Logic tags can be replaced by JSTL tags.

bean:cookie Replacement Example

The following snippet shows the basic usage of the cookie tag from the Bean Tag Library:

<bean:cookie id="category" name="cat"/>

The JSTL equivalent is as follows:

<c:set var="category" value="${cookie['cat'].value}"/>

This example accesses the cat cookie with a JSTL expression that makes use of the JSTL implicit cookie object.

bean:define Replacement Example

The following snippet shows the basic usage of the define tag from the Bean Tag Library:

<bean:define id="name" name="nameObj"/>

The JSTL equivalent is as follows:

<c:set var="name" value="${nameObj}"/>
bean:header Replacement Example

The following snippet shows the basic usage of the header tag from the Bean Tag Library:

<bean:header id="browser" name="User-Agent"/>

The JSTL equivalent is as follows:

<c:set var="browser" value="${header['User-Agent']}"/>

This example accesses the "User-Agent" header with a JSTL expression that makes use of the JSTL implicit header object.

bean:include Replacement Example

The following snippet shows the basic usage of the include tag from the Bean Tag Library:

<bean:include id="yahooContents" href="http://www.yahoo.com/"/>

The JSTL equivalent is as follows:

<c:import var="yahooContents" url=" http://www.yahoo.com/"/>
bean:parameter Replacement Example

The following snippet shows the basic usage of the parameter tag from the Bean Tag Library:

<bean:parameter id="color" name="clr"/>

The JSTL equivalent is as follows:

<c:set var="color" value="${param['clr']}"/>

This example accesses the clr parameter with a JSTL expression that makes use of the JSTL implicit param object.

bean:write Replacement Example

The following snippet shows the basic usage of the write tag from the Bean Tag Library:

<bean:write name="bizObj"/>

The JSTL equivalent is as follows:

<c:out value="${bizObj}" />
logic:empty Replacement Example

The following snippet shows the basic usage of the empty tag from the Logic Tag Library:

<logic:empty name="results">Your search yielded no results.</logic:empty>

The JSTL equivalent is as follows:

<c:if test="${empty results}">Your search yielded no results.</c:if>
logic:equal Replacement Example

The following snippet shows the basic usage of the equal tag from the Logic Tag Library:

<logic:equal name="count" value="0">Count is zero.</logic:equal>

The JSTL equivalent is as follows:

<c:if test="${count == 0}">Count is zero.</c:if>
bean:greaterEqual Replacement Example

The following snippet shows the basic usage of the greaterEqual tag from the Logic Tag Library:

<logic:greaterEqual name="count" value="5">Count is greater than or equal to five.</logic:greaterEqual>

The JSTL equivalent is as follows:

<c:if test="${count >= 5}">Count is greater than or equal to five.</c:if>
logic:greaterThan Replacement Example

The following snippet shows the basic usage of the greaterThan tag from the Logic Tag Library:

<logic:greaterThan name="count" value="5">Count is greater than five.</logic:greaterThan>

The JSTL equivalent is as follows:

<c:if test="${count > 5}">Count is greater than five.</c:if>
logic:iterate Replacement Example

The following snippet shows the basic usage of the iterate tag from the Logic Tag Library:

<logic:iterate id="result" collection="<%=results%>">Result: <%=result%><br></logic:iterate>

The JSTL equivalent is as follows:

<c:forEach var="result" items="${results}">Result: <c:out value="${result}"/></c:forEach>
logic:lessEqual Replacement Example

The following snippet shows the basic usage of the lessEqual tag from the Logic Tag Library:

<logic:lessEqual name="count" value="5">Count is less than or equal to five.</logic:lessEqual>

The JSTL equivalent is as follows:

<c:if test="${count <= 5}">Count is less than or equal to five.</c:if>
logic:lessThan Replacement Example

The following snippet shows the basic usage of the lessThan tag from the Logic Tag Library:

<logic:lessThan name="count" value="5">Count is less than five.</logic:lessThan>

The JSTL equivalent is as follows:

<c:if test="${count < 5}">Count is less than five.</c:if>
logic:notEmpty Replacement Example

The following snippet shows the basic usage of the notEmpty tag from the Logic Tag Library:

<logic:notEmpty name="results">Your search returned results!</logic:notEmpty>

The JSTL equivalent is as follows:

<c:if test="${!empty results}">Your search returned results!</c:if>
logic:notEqual Replacement Example

The following snippet shows the basic usage of the notEqual tag from the Logic Tag Library:

<logic:notEqual name="count" value="0">Count is not equal to zero.</logic:notEqual>

The JSTL equivalent is as follows:

<c:if test="${count != 0}">Count is not equal to zero.</c:if>
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值