This week's book giveaway is in the OO, Patterns, UML and Refactoring forum. We're giving away four copies of Refactoring for Software Design Smells: Managing Technical Debt and have Girish Suryanarayana, Ganesh Samarthyam & Tushar Sharma on-line! See this thread for details.
I am new to struts and coderanch as well. I got a problem and I am not getting any way out. Please help me.
I want to create a JSP file which will show a drop-down list fetching data from database (I am using it in struts 1.3). For example I want to show list of countries in a drop-down. Now I can do that by putting all the logic for connecting to the database, fetching the resultset, iterate over resultset to show the dropdown. But I don't really want to put any such coding inside my JSP.
I have heard of DAO, DTO, and I have studied on it. But I have no clue how it can help me. Please help me. If possible, please provide me an example.
You can take example of this tutorial drop down and try to implement it with database. Though if you face any difficulties let us know we will help you.
Joined: Sep 08, 2012
Thanks for your reply. The example is pretty cool! I understood it completely. But I want to create the drop-down from database data, I don't want some kind of hard coding or putting the whole logic (connect to database, fetch resultset, iterate over it etc) inside my JSP. Can you please guide me in that way?
kartic sahoo wrote: I don't want some kind of hard coding or putting the whole logic (connect to database, fetch resultset, iterate over it etc) inside my JSP. Can you please guide me in that way?
Nor should you. JSP's should only be used for presentation logic. All the business logic should go in the Action and it's supporting classes. Basically what you do is have the action do all the work getting the data you want to display, associating it with the session or request, then the JSP tags pick it up from there.
You can get some idea from the example. You can get the any collection fill it from the database in action and then send it to the jsp, and then you can display it on the jsp.
Whole purpose was to give you some idea about the drop down only remain part is how you fill drop down with the database i think which you can do.Put some efforts and come back with the any errors if you are getting.we will help you.
Joined: Sep 08, 2012
Hi Joe, Jatan
Your explanation really helped me to solve my issue. Thanks a lot guys.