如何在jsp中以选中状态从数据库中检索单选按钮值 [英] How to retrieve radio button value from database in checked state in jsp

查看:440
本文介绍了如何在jsp中以选中状态从数据库中检索单选按钮值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何在jsp中检索选中状态的单选按钮值?从数据库更新单选按钮时.

How to retrieve radio button values with checked state in jsp ? while updating radio button from data base.

Male <input type="radio" name="R1" value="<%=rs.getString("gender")%>">
Female <input type="radio" name="R1" value="<%=rs.getString("gender")%>"> 

如果在数据库中其母头应处于选中状态,则母头单选按钮 其他男性单选按钮 它不会不检查任何值

If in database its female it should be in checked state female radio button else male radio button its not checking the value for none

推荐答案

尝试使用 JSTL & EL 而不是Scriplet元素.对于数据库访问,请使用JSTL SQL标记库,或者最好在Servlet中移动数据库代码.

Try to use JSTL & EL instead of Scriplet elements. For database access use JSTL SQL Tag library or it's better to move the database code in the Servlet.

尝试使用 CSS输入广播选中的属性

示例代码:

<%@ 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>>

看看类似的帖子

对于复选框值,单个值可以正确显示,但是当多个值不显示任何值时.

For check box values single value its show properly but when it multiple values showing nothing.

使用contains方法检查字符串.

check the string using contains method.

示例代码:

<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>>

这篇关于如何在jsp中以选中状态从数据库中检索单选按钮值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆