File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Servlets and the fly likes dynamic drop down boxes Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Servlets
Bookmark "dynamic drop down boxes" Watch "dynamic drop down boxes" New topic
Author

dynamic drop down boxes

liliya woland
Ranch Hand

Joined: Apr 11, 2006
Posts: 134
Hello everyone,
I have a rather long list of select options, and I also have a mysql table that contains that very same data. I'd like to be able to streamline the data from the table into my select menu.
I know enough of .jsp (and some java) to read data from a table but don't know enough to do something like this. I know that I need to write a bean, but that's about all. Could anyone please refer me to any code examples so I could see what needs to happen? Thanks in advance.
vjy chin
Ranch Hand

Joined: Feb 17, 2005
Posts: 279
Hi,
One simple way is to connect to the database and get the values and store them in an array or arraylist.
The inside the select box, you just need to iterate the array or arraylist.



Hope this helps
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 60780
    
  65

Though preferably with the JSTL rather than scriptlets.


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
liliya woland
Ranch Hand

Joined: Apr 11, 2006
Posts: 134
Hi again,
I did try the code above and for some reason my options get populated with "vOptions.get(i)" instead of data.
I understand the problem has to do with my syntax, but could someone tell me please what syntax to use to get the array data out?
....
Vector vOptions = new Vector();
while(rs.next()){

vOptions.addElement(rs.getString(1));
}
.... then:

<select name="T50">
<%
for (int i = 0; i< vOptions.size(); i++) {
%>
<option value="<%=vOptions.get(i)%>">vOptions.get(i)</option>
<%
}
%>
</select>
liliya woland
Ranch Hand

Joined: Apr 11, 2006
Posts: 134
I got it! ... Just had to do <%=vOptions.get(i)%>
vjy chin
Ranch Hand

Joined: Feb 17, 2005
Posts: 279
OOPS, Sorry I forgot the <%= %> .
Good you noticed it and got the results.

Thanks
mamidi subrahmanyam
Greenhorn

Joined: Jun 29, 2005
Posts: 18
Hi liliya

Better use ArrayList than Vector.

(if there is no problem with performance issues, then you can continue with Vector also)
[ April 13, 2006: Message edited by: mamidi subrahmanyam ]
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: dynamic drop down boxes
 
Similar Threads
limiting the size of a resultset - Breaking up large resultset into chunks
SQL Query
Is there a way to perform SQL queries on local data?
SQL query
oracle table caching in java Map