Struts2 比较struts 2中的属性值
我想将会话变量与struts if条件的测试方法中的属性值进行比较Struts2 比较struts 2中的属性值,struts2,Struts2,我想将会话变量与struts if条件的测试方法中的属性值进行比较 <s:property value="band"/> <s:if test="#session.bandname == property value"> <s:form action="BandPost"> <s:textarea key="post" accesskey="post">Write a post</s:textarea>
<s:property value="band"/>
<s:if test="#session.bandname == property value">
<s:form action="BandPost">
<s:textarea key="post" accesskey="post">Write a post</s:textarea>
<s:submit/>
</s:form>
</s:if>
发帖
我想将if条件中的上述属性值与#session.bandname值进行比较。我试过很多东西,但都不管用。有人能给我答案吗
谢谢。我想你可以很容易地解决这个问题
<c:set var="varForComparison" value="ABC" scope="page"></c:set>
<c:if test="${ sessionScope.varInSession eq pageScope.varForComparison }">
// DO WHAT YOU HAVE TO
</c:if>
//做你该做的
您甚至可以像这样直接在请求中比较bean
<c:if test="${ sessionScope.varInSession eq requestScope.beanInRequest.propertyToCompare }">
// DO WHAT YOU HAVE TO
</c:if>
//做你该做的
另外,如果您想要多个条件,如if-else梯形图,则可以使用此选项
<c:choose>
<c:when test=""></c:when>
<c:otherwise></c:otherwise>
</c:choose>
在c:choose中,您可以使用任意数量的c:when。
核心JSTL+表达式语言帮助很大。
希望有帮助。您只需参考该属性即可。在操作中只需要使用公共字符串getBand()方法
<s:property value="band"/>
<s:if test="%{#session.bandname == band}">
<s:form action="BandPost">
<s:textarea key="post" accesskey="post">Write a post</s:textarea>
<s:submit/>
</s:form>
</s:if>
发帖
如果bandname是字符串,请使用字符串方法(如“equals”)。。。ie:test=“#session.bandname.equals(propertyValue)”。我想在测试条件下获得“”值。