gpt4 book ai didi

jsp - Struts 不会正确评估 if 语句。如何评价struts 2 s :if?

转载 作者:行者123 更新时间:2023-11-28 23:36:55 24 4
gpt4 key购买 nike

我有三个单选按钮:

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

我的 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/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com