drop down list
hiya I was wondering if any one could possibly help me....Im quite new to servlets so all the help I can get will be much appreciated.
currently I have a HMTL form that has a drop down list that a user can choose a value from. now how does a servlet read in that value the user chooses?
Many thanks
R123
[328 byte] By [
r123a] at [2007-10-2 13:24:15]

A servlet can get any form data the user has entered via the following:
String paramValue = request.getParameter("fieldName");
If the field has multiple values (e.g. checkboxes with the same name where multiple values may be checked), you would use the following:
String[] paramValues = request.getParameterValues("fieldName");
hiya i did as you said however i an not picking up what the user chooses.
in this program ive written i want the user to choose a value from the drop down list and then in the servlet i want the user to just print what the user selected. plz help as i dont know what im doing wrong!!!!!!!!!
heres the html:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<!--
<HTML><HEAD><TITLE>Collecting drinks</TITLE></HEAD>
<BODY BGCOLOR="#FDF5E6">
<H1 ALIGN="CENTER">Collecting drinks</H1>
<FORM ACTION="http://localhost:8080/Servlet/ThreeParams">
<select name="test">
<option value="Milk">Fresh Milk</option>
<option value="Cheese">Old Cheese</option>
<option value="Bread">Hot Bread</option>
</select>
<CENTER><INPUT TYPE="SUBMIT"></CENTER>
</FORM>
</BODY></HTML>
and heres the servlet im using;
import java.io.*;
import javax.servlet.*;
import javax.servlet.http.*;
public class ThreeParams extends HttpServlet {
public void doGet(HttpServletRequest request,
HttpServletResponse response)
throws ServletException, IOException {
response.setContentType("text/html");
PrintWriter out = response.getWriter();
String docType =
"<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.0 " +
"Transitional//EN\">\n";
String[] drink = request.getParameterValues("test");
out.println("<HTML><HEAD><TITLE>Emai List.</TITLE>");
out.println("</HEAD>");
out.println("<BODY bgColor=blanchedalmond text=#008000 topMargin=0>");
out.println("<P align=center><FONT face=Helvetica><FONT color=fuchsia style=\"BACKGROUND-COLOR: white\"><BIG><BIG>List of drinks.</BIG></BIG></FONT></P>");
out.println("<P align=center>");
out.println("<H3>You chose from the list:" + drink + "<H3>" );
}
}
many thanks for your help
r123a at 2007-7-13 11:02:48 >
