This week's book giveaways are in the Java EE and JavaScript forums.
We're giving away four copies each of The Java EE 7 Tutorial Volume 1 or Volume 2(winners choice) and jQuery UI in Action and have the authors on-line!
See this thread and this one 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


Win a copy of The Java EE 7 Tutorial Volume 1 or Volume 2 this week in the Java EE forum
or jQuery UI in Action in the JavaScript forum!
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: 61092
    
  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]
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: obtaining dropdown list items from mysql database in jsp