Struts不会正确评估if语句。如何评估struts 2:如果?

时间:2014-05-26 12:43:33

标签: jsp tomcat struts2 radio-button

我有三个收音机按钮:

<input type="radio" name="is_active" value="true">Active&nbsp;&nbsp;&nbsp;
<input type="radio" name="is_active" value="false">Inactive&nbsp;&nbsp;&nbsp;
<input type="radio" name="is_active" value="both" checked>Both<br>

然后是一些JSP。我写的时候:

<%=request.getParameter("is_active")%>

我得到&#34;两者&#34;,&#34; true&#34;或&#34;假&#34;在我的HTML中。但是当我写道:

<s:if test='%{#request.getParameter("is_active") == ("both")}'>

&lt;%= request.getParameter(&#34; is_active&#34;)%&gt;的输出总是:真或假或两者兼而有之。这三个选项之一。 即使我选择&#34; Both&#34;服务器也不会进入if块。单选按钮。有什么问题?

1 个答案:

答案 0 :(得分:0)

您正在OGNL表达式中使用Java比较。使用equals方法在Java中比较字符串。

<s:if test='#request.getParameter("is_active").equals("both")'> 

或与OGNL比较

<s:if test="#parameters.is_active[0] == 'both'">
相关问题