Manas
Manas

Reputation: 109

Dynamically populate a dropdown menu from database through JSTL

I have the following setup for my web-app:

1.) A Bean class.
2.) A DAO class that returns an arraylist containing Bean.
3.) A JSP page that has a dropdown menu.

I need to populate this dropdown menu from arraylist created in step 2. I don't know much about JSTL.I managed to populate my dropdown through scriptlets (using for each loop and iterating over the arraylist stored in session).
Now I need to free my code from scriptlets. Should I learn JSTL or use AJAX (or jquery)? Also do I need to call a servlet first to return an arraylist, in case I plan to use <jsp:useBean> tag?

Upvotes: 0

Views: 5180

Answers (1)

c_uld
c_uld

Reputation: 81

<select>
     <c:forEach var="item" items="${list}">
          <option><c:out value="${item}"/></option>
     </c:forEach>
</select> 

In regards to your second question. Yes, you can call request.setAttribute(...) and use the RequestDispatcher to forward to the JSP page which then uses the useBean tag.

Upvotes: 1

Related Questions