Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/jsp/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Jsp JSTL单选按钮显示,无论何时条件如何_Jsp_Jstl - Fatal编程技术网

Jsp JSTL单选按钮显示,无论何时条件如何

Jsp JSTL单选按钮显示,无论何时条件如何,jsp,jstl,Jsp,Jstl,我正在制作一个有单选按钮的应用程序。目标是记住用户输入的内容,并在返回到同一页面时对其进行跟踪。但是,无论我的when语句是真是假,按钮仍将显示。这是代码 <c:choose> <c:when test="${grace == 'off'}"> <input type="radio" id="grace" name="grace"/> </c:when> <c:when test="${grac

我正在制作一个有单选按钮的应用程序。目标是记住用户输入的内容,并在返回到同一页面时对其进行跟踪。但是,无论我的when语句是真是假,按钮仍将显示。这是代码

<c:choose>
    <c:when test="${grace == 'off'}">
           <input type="radio" id="grace" name="grace"/>
    </c:when>
     <c:when test="${grace == 'on'}">
         <input type="radio" id="grace" name="grace" checked="checked"/>
     </c:when>
</c:choose>

即使在我的java应用程序中grace属性被设置为off,两个单选按钮仍然被输出。我的代码有什么问题?我如何更改它,以便当属性grace等于off时,按钮将被取消选中,而当属性grace等于on时,按钮将被选中。谢谢大家!

如果这是错误的来源,请注意

    <?xml version="1.0" encoding="ISO-8859-1" ?>
<jsp:root xmlns:jsp="http://java.sun.com/JSP/Page" xmlns:c="http://java.sun.com/jsp/jstl/core"  version="2.0">
    <jsp:directive.page contentType="text/html; charset=ISO-8859-1" 
        pageEncoding="ISO-8859-1" session="false"/>
    <jsp:output doctype-root-element="html"
        doctype-public="-//W3C//DTD XHTML 1.0 Transitional//EN"
        doctype-system="http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"
        omit-xml-declaration="true" />
<html xmlns="http://www.w3.org/1999/xhtml">


首先,你不应该有两个单选按钮<“代码>已选中”应根据布尔值进行设置,然后您有一行代码,共8行。至于这不起作用的原因,您没有提供设置了
grace
的任何代码,也没有检查其实际值
可用于调试。我已调试了我的grace值,并在正确的情况下将其正确设置为on和off。如何使选中集依赖于布尔值?当我将checked设置为false时,按钮仍在检查中。您可以使用三元语句,如:
checked=“${grace eq'on'?“checked':”}
。如果你不熟悉,基本上是
test?(如果测试为真,则返回此项):(如果测试为假,则返回此项)
谢谢。什么值应该被选中以使其不被选中,因为无论我将其设置为什么,null、false、empty或只是包含checked,都会导致按钮被选中。啊,对。这在HTML中有点反常,是一个糟糕的设计选择,选中的
值不重要。如果选中了
,唯一重要的事情就是存在。所以这应该在“?”checked':''}
上起作用,您可以省略
checked=