http://www.yahoo.com/search?musicHere, the text field contains the string "music".
<html> <head><title>Test Post</title> <body> <form action="http://localhost:8019/servlets/Testform" method="post"> Enter a string: <input type="text" name="param1"> And then press "Go": <input type="submit" value="Go"> </form> </body> </html>NOTE: we will not cover html forms here. For details, see my tutorial on HTML.
import javax.servlet.*; import javax.servlet.http.*; import java.io.*; import java.util.*; public class TestForm extends HttpServlet { public void doPost (HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException { // Set the content type of the response. resp.setContentType ("text/html"); // Create a PrintWriter to write the response. java.io.PrintWriter out = new PrintWriter (resp.getOutputStream()); // The first part of the response. out.println (""); out.println ("Test "); out.println (""); // Now get the parameters and output them back. out.println ("Request parameters: "); Enumeration e = req.getParameterNames(); while (e.hasMoreElements()) { String name = (String) e.nextElement(); String value = req.getParameter (name); if (value != null) out.println ("