The HTTP request is divided into two types, get, and post, in the servlet, there is a doget () and dopost () method, the service () method is used to be responsible for the dispatch of these two methods.
* Environment configuration required to run servlet
The servlet container, which is used here is Apache Tomcat4.0.3, JDK1.4.2. When compiled, servlet. *, Servlet.http. * Can't find it, then copy the tomcat directory /common/lib/servlet.jar to JDK directory / jre / lib / ext, and in ClassPath You can register.
* The easiest servlet // hello.javaimport java.io. *; Import javax.servlet. *; Import javax.servlet.http. *;
public class Hello extends HttpServlet {public void doGet (HttpServletRequest req, HttpServletResponse res) throws IOException, ServletException {res.setContentType ( "text / html"); PrintWriter out = req.getWriter (); out.println ( "" ); Out.println ("
Web.xml Description:
* The above servlet can only receive the GET request, add the receiving POST request function // Add the following method public dopost (httpservletRequest Req, httpservletRequest Req, httpservletResponse res) throws ioException, servletexception {doget (REQ, RES); // Call doget method}