如何将此Java代码翻译为Jstl标记?谢谢
String var;
if(condition 1 == true)
var="Hello1";
else
var="Hello2"
答案 0 :(得分:1)
您可以<c:choose>
与<c:when>
和&lt; c:otherwise
&gt;
<c:choose>
<c:when test="#{condition1}">
<c:set var="var" value="Hello1"/>
</c:when>
<c:otherwise>
<c:set var="var" value="Hello2"/>
</c:otherwise>
</c:choose>
答案 1 :(得分:1)
答案:
<%
pageContext.setAttribute("condtion", condtion);
%>
<c:choose>
<c:when test="${condition == true }">
<c:set var="var" value="Hello1" />
</c:when>
<c:otherwise>
<c:set var="var" value="Hello2" />
</c:otherwise>
</c:choose>