I want to bind the value to dropdownlist, the value is retrieved from database.
I want the result supposed to be as below:
<option value=Sick>Sick</option>
<option value=Funeral>Funeral</option>
<option value=Trip>Trip</option>
<option value=Others>Others</option>
But now I get the result as below :
<option value=Others>Others</option>
<option value=Others>Others</option>
<option value=Others>Others</option>
<option value=Others>Others</option>
Here is my java code :
while(rs.next()){
le.setReason(rs.getString("lr_name"));
arrLeave.add(le);
}
request.setAttribute("arrLeave", arrLeave);
Here is my JSP :
<c:forEach items="${arrLeave}" var="arrLeave">
<option value=${arrLeave.reason}>${arrLeave.reason}</option>
</c:forEach>
What is the problem ? thanks !
You have only a single
leclass instance, so will get n copies of whatever the last reason was.Create a new instance for each row in the result set: