我正在一个应用程序中工作,我从数据库中获取数据,我想根据值显示单选按钮中的数据,即我有一个雇用或不雇用的雇员状态。现在我从数据库中获取了employeementstatus。但是我无法在单选按钮中显示该值,就像有两个单选按钮,如果雇员使用了雇员,那么将使用未使用的收音机。这是我的代码
for(int i=0;i<existingProfile.size();i++) {
employmentStatus = existingProfile.get(i).getEmploymentStatus();
这里使用的状态是使用或未雇用。现在我在我的单选按钮中执行此操作
<tr>
<th>Current Employment status<span style='color: #FF0000; display: inline;'>*</span></th>
<% if(employmentStatus.equals("Employeed")) {%>
<td>
<input type="radio" name="employementStatus" value="<%=employmentStatus %>">Employeed
<input type="radio" name="employementStatus" value="Not Employeed">Not Employeed<br>
</td>
<%}else if(employmentStatus.equals("Not Employeed"))
{%>
<td>
<input type="radio" name="employementStatus" value="Employeed">Employeed
<input type="radio" name="employementStatus" value="Not Employeed">Not Employeed<br>
</td>
<%}
%>
</tr>
在这段代码中,问题是当我在检查单选按钮后提交值时,它将进入数据库。因为当我在out.println(emplyementstatus)时,我可以在jsp页面中看到emplyementstatus值。但是当我再次登录应用程序时从页面注销后,单选按钮被取消选中。但是我仍然能够在jsp页面中打印出雇员状态,它正在正常运行。
答案 0 :(得分:1)
将属性checked
添加到要显示的单选按钮。
这是代码。
<tr>
<th>Current Employment status<span style='color: #FF0000; display: inline;'>*</span></th>
<% if(employmentStatus.equals("Employeed")) {%>
<td>
<input type="radio" name="employementStatus" value="<%=employmentStatus %>" checked>Employeed
<input type="radio" name="employementStatus" value="Not Employeed">Not Employeed<br>
</td>
<%}else if(employmentStatus.equals("Not Employeed")){%>
<td>
<input type="radio" name="employementStatus" value="Employeed">Employeed
<input type="radio" name="employementStatus" value="Not Employeed" checked>Not Employeed<br>
</td>
<%}
%>
</tr>
答案 1 :(得分:0)
也许您可以尝试这样做以缩短您的代码。
<tr>
<td>
<input type="radio" name="employementStatus" value="<%=employmentStatus %>" <% if(employmentStatus.equals("Employeed")){%> checked <%}%>>Employeed
<input type="radio" name="employementStatus" value="Not Employeed" checked>Not Employeed<br>
</td>
</tr>