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]
# 1

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");

Gita_Weinera at 2007-7-13 11:02:48 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 2
When the user submits the form (you need to add a submit button for that), the servlet can read the parameters passed from the form - which will include the option that the user chose.
RichFearna at 2007-7-13 11:02:48 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 3

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 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 4
sorry i forget to mention that when i run the program i get the following error:You chose from the list:[Ljava.lang.String;@1a5f739plz let me know where im going wrongthx
r123a at 2007-7-13 11:02:48 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 5
This isn't an error. The[Ljava.lang.String;@1a5f739is due to you trying to output an array. It's an array because you're using getParameterValues, which returns an array of Strings. To just get the first value use getParameterValue instead, which just returns a String.
RichFearna at 2007-7-13 11:02:48 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...