aspose file tools*
The moose likes JSP and the fly likes working with drop down menus Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Soft Skills this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Java » JSP
Bookmark "working with drop down menus" Watch "working with drop down menus" New topic
Author

working with drop down menus

Raymond O'Leary
Greenhorn

Joined: Mar 23, 2004
Posts: 24
Hey there,
I'm having problems writing and reading from and into a pull down menu in jsp pages, with the data stored in an oracle database.
does anybody know of any good tutorials?
Or can someone help here?
Are my questions clear enough!?
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61756
    
  67

Since this is probably much more about the JSP dimension than JDBC, I'm moving this to the JSP forum.
See ya there!
[ March 24, 2004: Message edited by: Bear Bibeault ]

[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61756
    
  67

A lot depends on whether the options in the drop-down need to be real-time (fetched from the db every time so that it is always up to date) or whether the info can be loaded at app startup time and be done with it.
If the former I would:
1) In my controller servlet I would fetch the info from the DB and store it in a collection as a request attribute.
2) On the page, use the JSTL c:forEach action to iterate over the collection and emit the HTML options for the dropdown.
If the latter, I would replace step 1 with:
1) In a servlet context listener (which triggers when the context is loaded) I would read the data from the DB and store it in a collection in application scope (aka servlet context).
2) Same as above
Raymond O'Leary
Greenhorn

Joined: Mar 23, 2004
Posts: 24
Hey there,
This is an example of the non-dynamic menus:
<Html>
<body bgColor="WHITE" text = "MIDNIGHTBLUE">
<h3>Record your comments </h3>
<FORM NAME="logform"ACTION="addtolog.jsp"METHOD="post"ENCODE="application/x-www-form-urlencoded">
<br>
Project Group ID</font>
<input type="text" name="t1" size="10" maxlength="5"> Day
<select size="1" name="D2">
<option selected>1</option>
<option>2</option>
<option>31</option>
</select>
Month
<select size="1" name="D3">
<option selected>9</option>
<option>10</option>
<option>5</option>
</select>
Year<select size="1" name="D4">
<option selected>03</option>
<option>04</option>
</select></p>
center>
<TEXTAREA NAME="comments" COLS=40 ROWS=8></TEXTAREA></center><br>
<hr>
<center>
<input type="submit" name="submit" value="Add to the log">
or
<input type="reset" value="Clear this text box"> or
</center>
</form>
<FORM METHOD="LINK" ACTION="viewlog.jsp" target="_self">
<INPUT TYPE="submit" VALUE="View The Log">
</FORM>
</html>

So would it be possible to simply refer to whatever the value is within the menu using say:
Stmt.setString(4,request.getParameter("D2"));
Stmt.setString(5,request.getParameter("D3"));
Stmt.setString(6,request.getParameter("D4"));
etc.?
And regarding a dynamicly changing one, is it as simple as executing a query, saving the results in an resultSet and then
while(rs.next())
out.println("<select size=10><choice>"+ rs.getString(1)"</choice>");
out.println("<choice>"+ rs.getString(2)"</choice>");
If you need me to clarify all this just ask.
Thanks.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: working with drop down menus