Win a copy of Programmer's Guide to Java SE 8 Oracle Certified Associate (OCA) this week in the OCAJP forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

obtaining dropdown list items from mysql database in jsp

 
Kenneth Owino
Greenhorn
Posts: 23
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi! How can I get dropdown list items from mysql to my jsp page. Is it possible to use a servlet to connect to the database and fetch the values as an array and send them to the jsp which receives them in the dropdown list? some clue please cause this thing looks simple but I don't know how to go about with it
 
dileep keely
Ranch Hand
Posts: 108
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
1)From Data Access Layer hit the DB and get the result .
2)Place the obtained data into the arrayList (BusinessUtil/Layer)and also in some scope(request,session).
3)Forward to the JSP page.
4)Iterate using JSTL.

The below example will give you some idea. Do the scriplet part into the BusinessLayer.
index.jsp
-----------
<%
List dataBase = new ArrayList();
dataBase.add("test1");
dataBase.add("test2");
dataBase.add("test3");
request.setAttribute("list",dataBase);
%>
${test}
<c:forEach var="result" items="${list}">
<cut value="${result}"/><br>
</c:forEach>

Note: Avoid using the scriplets in the JSP .
 
Kenneth Owino
Greenhorn
Posts: 23
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thank you. I got it done. created a DAO, DTO and populated the JSP using JSTL forEach and EL
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 65115
89
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Nice. Using the JSTL and EL is far superior than using discredited scriptlets.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic