jsp - Is there any better approach to generate radio button? -


to generate dynamic radio button based on value in hobby.what is-

request.setattribute("hobby", null); //values of hobby can "hobby1" or "hobby2" or "hobby3" or null request.getrequestdispatcher("display.jsp").forward(request, response); 

in display.jsp generating radio button-

<tr>     <td >hobby1     <c:choose>      <c:when test='${hobby.equals("hobby1")}'>            <input type="radio"  value="hobby1" name="hobby" checked/>     </c:when>     <c:otherwise>     <input type="radio" value="hobby1" name="hobby"/>     </c:otherwise>     </c:choose>      </td>        <td >hobby2     <c:choose>      <c:when test='${hobby.equals("hobby2")}'>            <input type="radio"  value="hobby2" name="hobby" checked/>     </c:when>     <c:otherwise>     <input type="radio" value="hobby2" name="hobby"/>     </c:otherwise>     </c:choose>      </td>     <td >hobby3     <c:choose>      <c:when test='${hobby.equals("hobby3")}'>            <input type="radio"  value="hobby3" name="hobby" checked/>     </c:when>     <c:otherwise>     <input type="radio" value="hobby3" name="hobby"/>     </c:otherwise>     </c:choose>     </td> </tr> 

is there better approach generate radio button since writing static code each button.we checking each button?

yes, don't need jstl. el enough.

try

<input type="radio"  value="hobby3" name="hobby" ${(hobby == 'hobby3')?'checked':''} /> 

Comments