我有三个单选按钮:
<input type="radio" name="is_active" value="true">Active
<input type="radio" name="is_active" value="false">Inactive
<input type="radio" name="is_active" value="both" checked>Both<br>
然后是一些 JSP。当我写:
<%=request.getParameter("is_active")%>
我的 HTML 中出现“both”、“true”或“false”。但是当我写的时候:
<s:if test='%{#request.getParameter("is_active") == ("both")}'>
<%=request.getParameter("is_active")%> 的输出始终为:true 或 false 或两者兼而有之。这三个选项之一。 即使我选择“两者”单选按钮,服务器也不会进入 if block 。怎么了?
最佳答案
您正在 OGNL 表达式中使用 Java 比较。在 Java 中使用 equals
方法比较字符串。
<s:if test='#request.getParameter("is_active").equals("both")'>
或者与OGNL对比
<s:if test="#parameters.is_active[0] == 'both'">
关于jsp - Struts 不会正确评估 if 语句。如何评价struts 2 s :if?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23870470/