• 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
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

working with drop down menus

 
Greenhorn
Posts: 24
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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!?
 
Sheriff
Posts: 67746
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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 ]
 
Bear Bibeault
Sheriff
Posts: 67746
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 24
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
reply
    Bookmark Topic Watch Topic
  • New Topic