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

dynamically populate drop-down box?

 
Annette L'Heureux
Ranch Hand
Posts: 135
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I may be way off here, but is there a way to dynamically populate, using jsp, a drop-down box (a regular html form object)? I would need to access an oracle database, and pull up all the records in 1 column which would make up my drop-down list. I would need to dynamically do this, in case new records are ever added. Please tell me I'm not dreaming!!
thanks,
Annette
 
Kevin Adams
Greenhorn
Posts: 21
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Here's what we do: I hope this answers your question.
Once you get a connection to the file you need, simply loop through the file and write out the options to the web page...

Kevin
 
Annette L'Heureux
Ranch Hand
Posts: 135
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Kevin, I definetly understand the idea! Now I'll just play around with it and see if I can get it to work. Do you put your code in a seperate servlet?
Thanks again!
Annette
 
Annette L'Heureux
Ranch Hand
Posts: 135
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
How do I get that code to run when a page is loaded?
The basic idea for me is that I will have some kind of link on the left, and it will load the new page on the right, but I need the drop-down box to be populated right away. So is there a way to get code to run on startup or something similar?
 
Darryl McCool
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The code in the JSP will be run as soon as you hit the JSP with your browser. So when the browser is ready to render the HTML in the JSP to the screen, the database has already been accessed and the <OPTION> tags have already been created from the data. The page is rendered with the drop-down box populated with this data.
 
maha anna
Ranch Hand
Posts: 1467
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Annette,
It is always good idea to minimize Java code in .jsp file. Especially dealing with DBConnection,database etc. Put those logic in a Java bean and keep it separate.
Please take a look at Frank's sample code in this discussion. You may get some idea.
http://www.javaranch.com/ubb/Forum7/HTML/001041.html
regds
maha anna
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 64629
86
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Sudhir Pawar,
Your post was moved to a new topic.
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic