【发布时间】:2013-03-19 15:08:25
【问题描述】:
我有一个 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>
假设我从数据库中获取单选按钮的值为“nC”,现在如何自动选择第二个单选按钮。
我试过了:
<input type="radio" id="new" value="n" <s:if test="${patientSoapBean.radioInnerSubjective == 'n'}">CHECKED</s:if> name="patientSoapBean.radioInnerSubjective"/><label for="new">New</label>
但我收到错误:
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
【问题讨论】:
-
我想我需要为此添加条件,但我不知道语法。
-
代码显示不够完整,无法给出完整答案。当您遍历不同的可能答案时,您需要检查从数据库中检索到的保存值是否设置为当前答案的值。如果是,您需要将
checked='checked'添加到单选按钮的输入标签中。有很多方法可以做到这一点。 -
你能指出我正确的语法吗?因为我很难弄清楚。我已经检查过,当我从数据库中取回值时,它反映了 pSB.radioInnerSubjective='nC',但是第二个选项(用于 'nC' 的选项没有得到检查。)。请帮帮我。
-
你能展示更多你的代码吗?例如,你是如何得到答案的?
-
我使用 ${} 通过 valuestack 从 action 类中获取值。例如
<input value="${pSB.patientID }" style="display: none" name="pSB.patientID"></input>
标签: jsp struts2 radio-button el struts-tags