Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Cloud/Virtualization forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

How to create dropdown fetching data from database?

 
kartic sahoo
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 299
Eclipse IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 9258
10
Linux Mac OS X Windows
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
jatan bhavsar
Ranch Hand
Posts: 299
Eclipse IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Joe, Jatan

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

Kartic
 
Devendra Bhati
Greenhorn
Posts: 19
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.

 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic