Java Reference
In-Depth Information
L ISTING 5.1
Continued
String[] movies = request.getParameterValues(“movie”);
if ( movies != null ) {
for ( int x = 0; x < movies.length; x++ ) {
out.println(movies[x] + “<BR>”);
}
}
out.println(“</body></html>”);
out.close();
}
//Get Servlet information
public String getServletInfo() {
return “HiddenFieldServlet Information”;
}
}
When you have this servlet installed, open your browser to the servlet's URL. The URL on my
local box is listed as follows:
http://localhost/djs/servlet/HiddenFieldServlet
When the servlet is loaded, you should only see a Submit button. If you view the current
HTML source, you will see a listing similar to this snippet:
<html>
<head><title>HiddenFieldServlet</title></head>
<body>
<FORM ACTION=”/djs/servlet/HiddenFieldServlet” METHOD=”POST”>
<INPUT TYPE=”hidden” NAME=”user” VALUE=”James”>
<INPUT TYPE=”hidden” NAME=”session” VALUE=”12892”>
<INPUT TYPE=”hidden” NAME=”movie” VALUE=”Happy Gilmore”>
<INPUT TYPE=”hidden” NAME=”movie” VALUE=”So I Married an Axe Murderer”>
<INPUT TYPE=”hidden” NAME=”movie” VALUE=”Jaws”>
<INPUT TYPE=”submit” VALUE=”Submit”>
</FORM>
</body></html>
5
Notice the hidden fields. Now click the Submit button. The form invokes the doPost() method of
the HiddenFieldServlet . This method parses the hidden fields out of the request and displays
them in a “shopping cart” listing. Figure 5.1 shows the results of the HiddenFieldServlet 's
doPost() method.
 
Search WWH ::




Custom Search