aspose file tools*
The moose likes Struts and the fly likes How to create dropdown fetching data from database? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Frameworks » Struts
Bookmark "How to create dropdown fetching data from database?" Watch "How to create dropdown fetching data from database?" New topic
Author

How to create dropdown fetching data from database?

kartic sahoo
Greenhorn

Joined: Sep 08, 2012
Posts: 4
Hi,

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.

Thanks,
Kartic
jatan bhavsar
Ranch Hand

Joined: Jul 23, 2008
Posts: 296

Hi Kartic,

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.

Regards
Jatan
kartic sahoo
Greenhorn

Joined: Sep 08, 2012
Posts: 4
Hi Jatan,

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?

Thanks,
Kartic
Joe Ess
Bartender

Joined: Oct 29, 2001
Posts: 8710
    
    6

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.


"blabbing like a narcissistic fool with a superiority complex" ~ N.A.
[How To Ask Questions On JavaRanch]
jatan bhavsar
Ranch Hand

Joined: Jul 23, 2008
Posts: 296

Hi Kartic ,

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.

Regards
Jatan
kartic sahoo
Greenhorn

Joined: Sep 08, 2012
Posts: 4
Hi Joe, Jatan

Your explanation really helped me to solve my issue. Thanks a lot guys.

Kartic
Devendra Bhati
Greenhorn

Joined: Dec 27, 2012
Posts: 19
Hi Kartic,
I'm doing the same problem ..also posted to forum for getting help in my code so if possible can you send me your code..i'll go through that and learn.

 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: How to create dropdown fetching data from database?
 
Similar Threads
How to select a value in the drop down list with value getting from database?
servlet or jsp page with prefilled forms
How to retain selected content after post on same page
Help Needed: Search/Filter on a Datatable for displaying records.
How to retrieve data from database when ever select in drop down list?