|
|||||
|
For longer forms with more data, the GET method is not always appropriate. Fortunately, servlets support POST method input just as easily. To convert our MyServlet to process POST method input, we implement the servlet's doPost() method as follows: import javax.servlet.*;
import javax.servlet.http.*;
// MyServlet.java
public class MyServlet extends HttpServlet
{
public void doGet ( HttpServletRequest req, HttpServletResponse res )
throws ServletException, IOException {
String name = req.getParameter("name");
res.setContentType( "text/html");
PrintWriter out = res.getWriter();
out.println( "<html><body>" );
out.println( "Hello there, " + name);
out.close();
}
public void doPost ( HttpServletRequest req, HttpServletResponse res )
throws ServletException, IOException {
res.setContentType( "text/html");
PrintWriter out = res.getWriter();
out.println( "<html><body>" );
out.println( "Your post has been received:<BR><BR>");
out.println(req.getParameter("name"));
out.println( req.getParameter("address"));
out.println( req.getParameter("city"));
out.println( req.getParameter("phone"));
out.close();
}
}
You could use the following HTML form to post data to this servlet. <FORM METHOD=POST ACTION=http://www.yourdomain.com/servlet/MyServlet"> <INPUT TYPE=text NAME=name> Name<BR> <INPUT TYPE=text NAME=address> Address<BR> <INPUT TYPE=text NAME=city> City<BR> <INPUT TYPE=text NAME=phone> Phone<BR> <INPUT TYPE=submit> Note: MMA technical support staff cannot provide
troubleshooting of problems with third-party CGI scripts including but
not limited to: Perl scripts, C/C++ binaries, PHP or web/database integration
unless these services are specifically contracted. For these services,
please see our Quote Request Form. |
|||||
|
||||||
Copyright
© 1995-2000
Motivational Marketing Associates, LLC
All Rights Reserved.