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