![]() |
![]() |
![]() |
![]() |
![]() |
|
To make use of namevalue pairs, you
deploy the getParameter method, with the request as the target.
In the following definition of ProcessCriticFormServlet, the
doGet is a stub. It merely constructs a table that echos the
arguments back to the browser.
import java.io.*;
import javax.servlet.*;
import javax.servlet.http.*;
public class ProcessCriticFormServlet extends HttpServlet {
public void doGet (HttpServletRequest request,
HttpServletResponse response)
throws ServletException, IOException {
// Process arguments
String title = request.getParameter("title");
String script = request.getParameter("script");
String acting = request.getParameter("acting");
String direction = request.getParameter("direction");
// Writing preparation
response.setContentType("text/html");
PrintWriter webWriter = response.getWriter();
// Writing HTML page
webWriter.println("<HTML><HEAD><TITLE>");
webWriter.println("You were the critic!");
webWriter.println("</TITLE></HEAD><BODY>");
webWriter.println("<h1>You have voted as follows for <u>"
+ title
+ "</u></h1>");
webWriter.println("<table cellpadding=5 border=1 >");
webWriter.println("<tr><td>Script<td>" + script);
webWriter.println("<tr><td>Acting<td>" + acting);
webWriter.println("<tr><td>Direction<td>" + direction);
webWriter.println("</table><p>");
webWriter.println(
"<a href=\""
+ response.encodeRedirectURL("/servlet/startcritic")
+ "\">"
);
webWriter.println("Click here</a> to vote again.");
webWriter.println("</BODY></HTML>");
webWriter.flush();
// Real work goes here
}}