How to retrieve radio button value from database in checked state in jsp

前端 未结 2 1163
深忆病人
深忆病人 2020-12-18 11:09

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

Male 

        
相关标签:
2条回答
  • 2020-12-18 11:46

    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.

    Try with the CSS Input Radio checked Property

    Sample code:

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

    Have a look at the similar post


    EDIT

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

    check the string using contains method.

    sample code:

    <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>>
    
    0 讨论(0)
  • 2020-12-18 11:52

    update Radio Button in jsp:- Code:- >Male

    >Female

    0 讨论(0)
提交回复
热议问题