Jsp 如何根据从数据库检索到的值检查单选按钮?

Jsp 如何根据从数据库检索到的值检查单选按钮?,jsp,struts2,radio-button,el,struts-tags,Jsp,Struts2,Radio Button,El,Struts Tags,我有一个JSP页面,在该页面中,我在数据库中保存所选单选按钮的表单和值。现在,我需要更新该页面,所有内容都显示出来,但单选按钮没有被选中。 我不知道如何在jsp上显示以前选择的单选按钮。我使用的是Struts2,Java Jsp代码: <div id="patientCondition"> <input type="radio" id="new" value="n" name="pSB.radioInnerSubjective" /><

我有一个JSP页面,在该页面中,我在数据库中保存所选单选按钮的表单和值。现在,我需要更新该页面,所有内容都显示出来,但单选按钮没有被选中。 我不知道如何在jsp上显示以前选择的单选按钮。我使用的是Struts2,Java

Jsp代码:

    <div id="patientCondition">
            <input type="radio" id="new" value="n" name="pSB.radioInnerSubjective" /><label for="new">New</label>
            <input type="radio" id="noChange" value="nC" name="pSB.radioInnerSubjective" /><label for="noChange">No Change</label> 
            <input type="radio" id="progressing" value="p" name="pSB.radioInnerSubjective" /><label for="progressing">Progressing</label>
            <input type="radio" id="notProgressing" value="nP" name="pSB.radioInnerSubjective" /><label for="notProgressing">Not Progressing</label>
    </div>

您不能在Struts2标记中使用
${…}
,您需要在
test
属性中交换
'
,以便与一个字符串进行正确比较

<input type="radio" id="new" value="n" <s:if test='patientSoapBean.radioInnerSubjective == "n"'>checked</s:if> name="patientSoapBean.radioInnerSubjective"/>
<label for="new">New</label>

新的
当然,对于
patientSoapBean
radionnersubjective
,您需要getter/setter


顺便说一句,Struts2有
标记,它将检查选中的单选按钮。

我想我需要为此添加条件,但我不知道语法。代码显示不足以给出完整答案。当您循环查看不同的可能答案时,您需要检查从数据库检索的保存值是否设置为cur值租赁答案。如果是,您需要将
checked='checked'
添加到单选按钮的输入标记。有很多方法可以做到这一点。您能告诉我正确的语法吗?因为我很难理解它。我已经检查过,当我从数据库中获取值时,它反映了pSB.radionnersubjective='nC',但第二个选项是(表示“nC”的代码未被选中。)。请帮我解决这个问题。您可以显示更多的代码吗?例如,您是如何获得答案的?我使用${}通过valuestack从action类获取值。例如,
Mar 28, 2013 6:07:54 PM org.apache.catalina.core.ApplicationDispatcher invoke
SEVERE: Servlet.service() for servlet jsp threw exception
org.apache.jasper.JasperException: /WEB-INF/views/patient_soap.jsp (line: 703, column: 44) According to TLD or attribute directive in tag file, attribute test does not accept any expressions
<input type="radio" id="new" value="n" <s:if test='patientSoapBean.radioInnerSubjective == "n"'>checked</s:if> name="patientSoapBean.radioInnerSubjective"/>
<label for="new">New</label>