Why this drop downlist in jsp is not running ? ( dropdownlist using loop in jsp ) -


i want drop down list in don't want write down every option line line. in case option year. getting current year , trying make options of list year 1990 current year using loop. not wroking...do have write line line option codes ? have run code on jsp page.

you can see jsp code here :

<select name = "year_select">     <%         int current_year = calendar.getinstance().get(calendar.year);         for(int year = 1990; year<=current_year; year++)         {     %>         <option> <% year %> </option>     <%           }     %> </select> 

use javaserver pages standard tag library instead of scriptlet in 21st century more easy use , less error prone.

sample code:

<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%> <%@ taglib uri="http://java.sun.com/jsp/jstl/fmt" prefix="fmt"%>  <jsp:usebean id="today" class="java.util.date" /> <fmt:formatdate pattern="yyyy" value="${today}" var="current_year" />  <select name="year_select">     <c:foreach begin="1990" end="${current_year}" var="year">         <option>${year}</option>     </c:foreach> </select> 

read more jsp jstl tag library tutorial


Comments

Popular posts from this blog

database - VFP Grid + SQL server 2008 - grid not showing correctly -

jquery - Set jPicker field to empty value -

.htaccess - htaccess convert request to clean url and add slash at the end of the url -