Here are the procedures in question (both part of one servlet)
getMasterset query's the database and returns an html page with
a select box.
The user should make a selection and press submit. This calls
a second procedure in the servlet to query the database and
return another select box, hopefully filled with data filtered
on the value of the first selection.
Most of this is just formatting tags by the way.
I don't know where to retrieve the value of the select box.
Can anyone help
protected void getMasterset(HttpServletRequest request, HttpServletResponse
response) throws ServletException, IOException {
HttpSession session = request.getSession(true);
/*if (session == null) {
printMessage(response, "Please enter the store first.");
return;
}*/
response.setContentType("text/html");
PrintWriter pw = response.getWriter();
pw.println("<html><body>");
pw.println("<p><font color=#8080C0 size=3 face=Arial><strong>" +
"This is a test.</strong></font></p>");
// Start html
pw.println("<head>");
pw.println("<meta http-equiv=Content-Type content=text/html;
charset=iso-8859-1>");
pw.println("<title>Delete an Association</title>");
pw.println("</head>");
//Start masterset
pw.println("<form name=form0
action=/snowservlet/SnowServlet?task=getCategory method=POST>");
pw.println("<table border=0 cellpadding=5>");
pw.println("<p><select name=masterset WIDTH=230 MULTIPLE size=1>");
for (int i = 0; i < mastersetsvec.size(); i ++) {
Masterset b = (Masterset)mastersetsvec.elementAt(i);
pw.println("<option
value="+b.MasterSetName+">"+b.MasterSetName+"</option>");
}
pw.println("</select></p>");
pw.println("<p><input type=submit name=Submit value=Submit></p>");
//Stop masterset
pw.println("</table></form></body></html>");
pw.close();
}
// get categorys
protected void getCategory(HttpServletRequest request, HttpServletResponse
response) throws ServletException, IOException {
HttpSession session = request.getSession(false);
/*if (session == null) {
printMessage(response, "Please enter the store first.");
return;
}*/
response.setContentType("text/html");
PrintWriter pw = response.getWriter();
pw.println("<html>");
pw.println("<body bgcolor=#FFFFFF>");
pw.println("<form name=form1>");
pw.println("<table width=49% cellpadding=0 cellspacing=0 border=0
bgcolor=#C0C0C0 align=center>");
pw.println("<tr valign=middle align=left>" +
"<td bgcolor=#000060 colspan=3 valign=top><font size=+1 color=#ffffff>Delete
a Document Association - Step 1</font></td>" +
"</tr>" +
"<tr>" +
"<td>A</td>" +
"<td>B</td>" +
"<td>C</td>" +
"</tr>" +
"<tr>" +
"<td>D</td>" +
"<td>E</td>" +
"<td>F</td>" +
"</tr>");
pw.println("</table>");
pw.println("<p><select name=category WIDTH=230 MULTIPLE size=1>");
for (int i = 0; i < categoryvec.size(); i ++) {
Category b = (Category)categoryvec.elementAt(i);
pw.println("<option
value="+b.CategoryName+">"+b.CategoryName+"</option>");
}
pw.println("</select></p>");
pw.println("</form></body></html>");
pw.close();
//end bw
}
Conor D'Arcy wrote:
> Hi,
> First let me see if I understand the question:
> say that your HTML select is set up as in this fragment..
> <HTML>...<BODY>...
> <FORM ACTION = "someservlet">...
> <SELECT SIZE = "1"
> NAME="SELECTVAL"><OPTION>First</OPTION><OPTION>Second</OPTION></SELECT>...
> <INPUT TYPE="SUBMIT">...
> </FORM>..
> </BODY>
> </HTML>
> My understanding is that when the user clicks on submit, you want
> 'someservlet' to find whether the user chose 'First' or 'Second' from the
> select. You then want to take the value of that choice and store it for
> later use. If my understanding is correct, you may wish to use the
> getParameter method in 'someservlet' and putting the result into a session
> variable:
> ...
> ...
> public void doPost(HttpServletRequest request, HttpServletResponse response)
> throws IOException, ServletException
> {
> HttpSession mySession=request.getSession(true);
> //We now have a session called mySession
> ...
> String UsersChoiceFromSelect = request.getParameter("SELECTVAL");
> //SELECTVAL was the NAME of the SELECT in the HTML above
> //for 2.1 API use the next line...
> mySession.putValue("SelectChoice",UsersChoiceFromSelect );
> //...or for 2.2 API uncomment the next line and use it instead
> //mySession.setAttribute("SelectChoice",UsersChoiceFromSelect );
> ...
> //Now when we want to retrieve the value that the user picked for SELECTVAL
> //in another servlet we refer to the session variable "SelectChoice"
> ...
> }
>
> -----Original Message-----
> From: Bill Wyza [mailto:[EMAIL PROTECTED]]
> Sent: Wednesday, June 14, 2000 6:35 AM
> To: [EMAIL PROTECTED]
> Subject: Servlet question on passing variables
>
> I have a servlet that generates a dynamic html page with a select box
> on it. The user must select an item from the list and press submit. I
> need
> to capture the value of the select box and pass it to another procedure
> in the servlet to create a second dynamic page.
>
> How to I get the value of the select box and keep it for later use?
>
> Bill
>
> ___________________________________________________________________________
> To unsubscribe, send email to [EMAIL PROTECTED] and include in the body
> of the message "signoff SERVLET-INTEREST".
>
> Archives: http://archives.java.sun.com/archives/servlet-interest.html
> Resources: http://java.sun.com/products/servlet/external-resources.html
> LISTSERV Help: http://www.lsoft.com/manuals/user/user.html
>
> ___________________________________________________________________________
> To unsubscribe, send email to [EMAIL PROTECTED] and include in the body
> of the message "signoff SERVLET-INTEREST".
>
> Archives: http://archives.java.sun.com/archives/servlet-interest.html
> Resources: http://java.sun.com/products/servlet/external-resources.html
> LISTSERV Help: http://www.lsoft.com/manuals/user/user.html
--
_________________________________________________________________
ORACLE CORPORATION http: //www.oracle.com
Bill Wyza
Staff Consultant, Internet Platform
Alliances Technical Services
Oracle Corporation Office: 714.445.4631
600 Anton Boulevard Fax: 714.444.8400
Suite 1400
Costa Mesa, Ca 92626 Email: [EMAIL PROTECTED]
_________________________________________________________________
___________________________________________________________________________
To unsubscribe, send email to [EMAIL PROTECTED] and include in the body
of the message "signoff SERVLET-INTEREST".
Archives: http://archives.java.sun.com/archives/servlet-interest.html
Resources: http://java.sun.com/products/servlet/external-resources.html
LISTSERV Help: http://www.lsoft.com/manuals/user/user.html