Win a copy of Kotlin in Action this week in the Kotlin forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

help me  RSS feed

 
jenni john
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • 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..
 
Ben Souther
Sheriff
Posts: 13411
Firefox Browser Redhat VI Editor
 
Akash Deep
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • 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">
<htmlptions collection="itemList" property="value" />
</html:select>
with this you can get.
 
Ben Souther
Sheriff
Posts: 13411
Firefox Browser Redhat VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
"Venkat",
Please check your private messages regarding an important administrative matter.
-Ben
 
Raghavan Muthu
Ranch Hand
Posts: 3389
Mac MySQL Database Tomcat Server
  • Mark post as helpful
  • send pies
  • 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:
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!