如何在jsp中检查带有检查状态的单选按钮值?同时从数据库更新单选按钮. Male input type="radio" name="R1" value="%=rs.getString("gender")%"Female input type="radio" name="R1" value="%=rs.getString("gender")%" 如果在
Male <input type="radio" name="R1" value="<%=rs.getString("gender")%>"> Female <input type="radio" name="R1" value="<%=rs.getString("gender")%>">
如果在数据库中它的女性它应该处于检查状态的女性单选按钮
别的男性单选按钮
它没有检查无值
试试CSS Input Radio checked Property
示例代码:
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%> <c:set var="gender" value="female"/> Male <input type="radio" name="R1" value="Male" <c:if test="${gender=='male'}">checked</c:if>> Female <input type="radio" name="R1" value="Female" <c:if test="${gender=='female'}">checked</c:if>>
看看类似的post
编辑
For check box values single value its show properly but when it multiple values showing nothing.
使用contains方法检查字符串.
示例代码:
<c:set var="medium" value="Hindi Kannada" /> English <input type="checkbox" name="C1" <c:if test="${medium.contains('English')}">checked</c:if>> Kannada <input type="checkbox" name="C1" <c:if test="${medium.contains('Kannada')}">checked</c:if>> Hindi <input type="checkbox" name="C1" <c:if test="${medium.contains('Kannada')}">checked</c:if>>