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!?
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
Joined: Mar 23, 2004
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.