Package cn.dragon.servlet; The following is the package for importing the corresponding Import java.io.IOException; Import Java.io.PrintWriter; Import javax.servlet.ServletException; Import Javax.servlet.http.HttpServlet; Import Javax.servlet.http.HttpServletRequest; Import Javax.servlet.http.HttpServletRe Sponse; /** * This is a sample of the first servlet * @author Cn.dragon */ public class Servletdemofirst extends HttpServlet { For handling get requests sent by the client public void doget (HttpServletRequest request, httpservletresponse response) Throws Servletexception, IOException { Response.setcontenttype ("text/html;charset=gb2312"); This statement indicates the format of the content sent to the client and the character encoding used. PrintWriter out = Response.getwriter (); Out.println ("Hello. "); Send data to client using the PrintWriter object method Out.close (); } For processing post requests sent by the client public void DoPost (HttpServletRequest request, httpservletresponse response) Throws Servletexception, IOException { Doget (request, response); The function of this statement is. Call the Doget () method for processing when the client sends a POST request } } |