0

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?

1 Answer 1

1
<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.

Sign up to request clarification or add additional context in comments.

2 Comments

So,for example,if I forward my arraylist named "dlist" from my servlet,and properties of my bean are "name" and "age",then my tag would be <select> <c:forEach var="item" items="${dlist}"> <option><c:out value="${item.name}"/></option> </c:forEach> </select> Is it correct?
Yes, that is correct. Just make sure that the attribute is also called dlist: request.setAttribute("dlist", dlist);

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.