Prentice Hall and Sun Microsystems. Personal use only; do not redistribute.
A.3 Handling the Client Request: Form Data
523
A.3 Handling the Client Request: Form Data
Reading Parameters
request.getParameter: returns first value
request.getParameterValues: returns array of all values
Example Servlet
ThreeParams.java
package coreservlets;
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 title = "Reading Three Request Parameters";
out.println(ServletUtilities.headWithTitle(title) +
"\n" +
"" + title + "
\n" +
"
" param1: "
+ request.getParameter("param1") + "\n" +
" param2: "
+ request.getParameter("param2") + "\n" +
" param3: "
+ request.getParameter("param3") + "\n" +
"\n" +
"