Struts不能正确计算if语句.如何计算struts2:if



我有三个单选按钮:

<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")%>

我得到"both", "true"或"false"在我的HTML。但是当我写:

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

<%=request.getParameter("is_active")%>的输出总是:true或false或两者兼有。这三个选项之一。即使我选择"Both"单选按钮,服务器也不会进入if块。怎么了?

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

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

或与OGNL比较

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

最新更新