This week's book giveaway is in the Mac OS forum.
We're giving away four copies of a choice of "Take Control of Upgrading to Yosemite" or "Take Control of Automating Your Mac" and have Joe Kissell on-line!
See this thread for details.
The moose likes JSP and the fly likes obtaining dropdown list items from mysql database in jsp Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


JavaRanch » Java Forums » Java » JSP
Bookmark "obtaining dropdown list items from mysql database in jsp" Watch "obtaining dropdown list items from mysql database in jsp" New topic
Author

obtaining dropdown list items from mysql database in jsp

Kenneth Owino
Greenhorn

Joined: Aug 09, 2010
Posts: 23
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

Joined: Jun 28, 2010
Posts: 91
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

Joined: Aug 09, 2010
Posts: 23
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

Joined: Jan 10, 2002
Posts: 61315
    
  66

Nice. Using the JSTL and EL is far superior than using discredited scriptlets.


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
 
GeeCON Prague 2014
 
subject: obtaining dropdown list items from mysql database in jsp