Please send questions to
st10@humboldt.edu .
/**
* st10PostOrGetOrder.java
*
* from: p. 166-167, Gittleman, "Internet Applications with the Java 2
* Platform"
*
* "Revises [st10GetOrder] to allow the user to order with
* a POST request as well as a GET request"
*
* (one advantage: "browser does not include the data with the POST request.
* Thus using POST instead of GET is essential to keep the data sent private.
* Data sent with a GET request is appended to the URL and displayed in the
* browser's address field.")
*
* modified by: Sharon Tuttle
* last modified: 5-7-01
**/
import java.io.*;
import javax.servlet.*;
import javax.servlet.http.*;
public class st10PostOrGetOrder extends HttpServlet
{
/* will handle a GET request */
public void doGet (HttpServletRequest req, HttpServletResponse resp)
throws ServletException, IOException
{
String message; // what was specified from form?
PrintWriter out; // text of response?
resp.setContentType("text/html");
out = resp.getWriter();
// "The getParameter() method returns the parameter entered
// in an HTML form or appended directly to a URL"
message = req.getParameter("Order");
// let's make this "nicer" if nothing is ordered
if ((message == null) || ( (message.trim()).equals("") ))
{
message = "nothing, please.";
}
// this servlet's response: "echo the order back to
// the user"
out.println("<html>");
out.println("<head><title>Get Order Servlet</title></head>");
out.println("<body><h1><strong>I'd like to order<br>");
out.println( message + "</strong></h1></body>");
out.close();
}
// will handle a POST request by "delegating any POST requests
// to the doGet() method"
public void doPost(HttpServletRequest req, HttpServletResponse resp)
throws ServletException, IOException
{
doGet(req, resp);
}
}