JSTL (c-tag) vs. STRUTS2 (S-label) label Common features

Source: Internet
Author: User

1. Condition label

Jstl

<c:ifTest= "${user.password = = ' Hello '}">      <C:choose>          <C:whenTest= "${user.age <=}">              <FontColor= "Blue"/>          </C:when>          <C:whenTest= "${user.age <= && user.age >">              <FontColor= "Red"/>         </C:when>          <c:otherwise>             <FontColor= "Green"/>          </c:otherwise>      </C:choose></c:if>

STRUTS2:

<s:ifTest= "#user. Age <=">     <FontColor= "Blue"/></s:if><S:elseifTest= "#user. Age <= && user.age >">     <FontColor= "Red"/></S:elseif>     <FontColor= "Green"/></S:else>

2. Iteration Labels
Jstl:

<C:foreachvar= "User"Items= "${users}">      <C:outvalue= "${user.username}"/></C:foreach><!--number of iterations fixed -<C:foreachvar= "I"begin= "1"End= "Ten"Step= "3">    <C:outvalue= "${i}"/></C:foreach><!--this loop is equivalent to the for (int i=1; i<10; i++), where step is the step of the iteration, which defaults to 1. -

STRUTS2:

<S:iteratorvalue= "#users"Status= "Stuts">     <s:ifTest= "#stuts. Odd = = True">   <!--determine if it is an odd line -          <S:propertyvalue= "UserName"/>      </s:if>      <S:else>          <S:propertyvalue= "PassWord"/></S:else></S:iterator>

3. URL-related tags

Jstl:

<!--Absolute Path -<C:importURL= "http://127.0.0.1:8080/hello/hello.jsp"/><!--relative Path -<C:importURL= "hello.jsp"/><!--Encode -<ahref= "<c:url value= ' hello.jsp ' ><c:param name= ' userName ' value= ' cyanbomb '/></c:url> '></a><!--passing parameters to the specified URL -<C:importURL= "hello.jsp"charencoding= "gb2312">      <C:paramname= "UserName"value= "Cyanbomb"/></C:import><!--URL Redirection -<C:redirectURL= "${myurl}"/><!--construct URL -<C:urlvalue= "Myurl"var= "hello.jsp"Scope= "Session"><C:paramname= "UserName"value= "Cyanbomb"/></C:url>

STRUTS2:

<ahref= ' <s:urlvalue= "/hello.jsp" />' >hello</a><BR/><S:urlID= "url"value= "/hello.jsp"><S:paramname= "Name">Cyanbomb</S:param></S:url><s:ahref= "%{url}">Hello</s:a>

Dismiss the question, list traversal problem

Like such a list, there are 3 records, each record contains two objects, I put the result set (lstrooms) request to the page, I want to traverse the display Rrmrooms ID, and rrmroomtype name. I use JSTL to achieve the following:

<Table>      <C:foreachvar= "rm"Items= "${lstrooms}">          <TR>              <TD>${rm[0].id}</TD>              <TD>${rm[1].name}</TD>          <TR>      </C:foreach></Table>

The STRUTS2 is implemented as follows:

<Table>      <S:iteratorvalue= "#lstRooms"Status= "Stat">          <TR>              <TD><S:propertyvalue= "#lstRooms [#stat. Index][0].id"/></TD>              <TD><S:propertyvalue= "#lstRooms [#stat. Index][1].name"/></TD>         <TR>      </S:iterator></Table>

JSTL (c-tag) vs. STRUTS2 (S-label) label Common features

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.