Add the JSTL Library as below

<%@taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/functions" prefix="fn" %>

Populating a Text Box

  <input name="txtUserName" id="txtUserName" type="text" value='<c:out value="${User.userName}"></c:out>'>

Populating a Dropdown List
Type 1

 <select name="cboAge" id="cboAge">
  <c:forEach begin="20" end="60" var="i">
    <option value="${i}" <c:if test="${i == User.age}">Selected</c:if>>${i}</option>    			
  </c:forEach>
 </select>

Type 2

 <select name="cboLocation" id="cboLocation">
   <option value="Chennai">Chennai</option>
   <option value="Bangalore">Bangalore</option>
   <option value="Mumbai">Mumbai</option>
  </select>

Javascript Code

$('document').ready(function(){
  $('#cboLocation').val('<c:out value="${User.location}"></c:out>');
});

Populating Radio buttons

<input name="rdoGender" type="radio" id="rdoMale" value="1" <c:out value="${User.gender == 1?'checked':''}"></c:out>><label for="rdoMale">Male</label>
<input name="rdoGender" type="radio" id="rdoFemale" value="0" <c:out value="${User.gender == 0?'checked':''}"></c:out>><label for="rdoFemale">Female</label>

Populating Check boxes

 <input name="chkSkills" type="checkbox" id="chkJava" value="Java" <c:if test="${fn:contains(User.skills, 'Java')}">Checked</c:if>><label for="chkJava">Java</label>    	
Posted in JSP.

Comments are closed.