• 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
  • Tim Cooke
  • paul wheaton
  • Ron McLeod
  • Jeanne Boyarsky
Sheriffs:
  • Paul Clapham
Saloon Keepers:
  • Tim Holloway
  • Roland Mueller
Bartenders:

help me

 
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
anybody please tell me how to add the contents of database to a dropdown menu...i'm using java and mysql..
 
Sheriff
Posts: 13411
Firefox Browser VI Editor Redhat
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
jenni,
Welcome to Javaranch.

Please see:
http://faq.javaranch.com/java/UseAMeaningfulSubjectLine
 
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi
In action form, you write a method to populate the dropdown menu in jsp.
in that method get the list of items and add to array list using LabelValueBean. Ex:itemList.add(new LabelValueBean(itemvalue, itemname)).
Put the itemList in to session. In Jsp use
<html:select property="itemname">
<html:options collection="itemList" property="value" />
</html:select>
with this you can get.
 
Ben Souther
Sheriff
Posts: 13411
Firefox Browser VI Editor Redhat
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
"Venkat",
Please check your private messages regarding an important administrative matter.
-Ben
 
Ranch Hand
Posts: 3389
Mac MySQL Database Tomcat Server
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Jhenni,

Understand that you need to have the values at hand to populate in the dropdown box or select control in HTML.

We know a way for getting the values at runtime ie., dynamically. JSP helps you to do that.

Now, how you will get the values from database? Obviously a Java code (it can be any class, servlet , model (Java Bean) which is aware of dealing with a database and retrieving).

Once you get the value you can assign the collection of values to a custom tag in case of Struts and other frameworks. In plain JSP, you can make use of scriptlets in the beginner's level with which you can just iterate it using an Iterator as you do in a plain Java class and assign the individual values for each "option" inside your "Select" control.

So your flow should be

Select Box in JSP <---> Java Bean / Servlet <---> Database.

Hope this helps! :thumb:
 
The happiness of your life depends upon the quality of your thoughts -Marcus Aurelius ... think about this tiny ad:
Clean our rivers and oceans from home
https://www.kickstarter.com/projects/paulwheaton/willow-feeders
reply
    Bookmark Topic Watch Topic
  • New Topic