Java Reference
In-Depth Information
L ISTING 4.1
Continued
String param = null;
// Iterate over the names, getting the parameters
while ( parameters.hasMoreElements() ) {
param = (String)parameters.nextElement();
out.println(“<BOLD>” + param +
“ : “ + request.getParameter(param) +
“</BOLD><BR>”);
}
out.println(“</body></html>”);
out.close();
}
//Get Servlet information
public String getServletInfo() {
return “FormServlet Information”;
}
}
As you look over this servlet, you will notice that it services both GET and POST requests. You
can invoke the FormServlet by encoding a URL string or by using a form. The HTML source,
used to invoke the servlet using the POST method, is shown in Listing 4.2.
L ISTING 4.2
Form.html Displays HTML Required to Invoke the Servlet Using the POST
Method
<HTML>
<HEAD>
<TITLE>
Chapter 4 Form
</TITLE>
</HEAD>
<BODY>
<FORM ACTION=http://localhost/djs/servlet/FormServlet
METHOD=POST>
<TABLE STYLE=”HEIGHT: 173px; WIDTH: 242px”>
<TR>
<TD>Last Name:</TD>
Search WWH ::




Custom Search