• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

How to create dropdown fetching data from database?

 
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Ranch Hand
Posts: 300
Eclipse IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Bartender
Posts: 9626
16
Mac OS X Linux Windows
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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: 300
Eclipse IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Joe, Jatan

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

Kartic
 
Greenhorn
Posts: 19
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.

 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic