Package CN. Dragon. servlet; // Import the corresponding package 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. httpservletresponse; /** * This is the first servlet example. * @ Author CN. Dragon */ Public class servletdemofirst extends httpservlet { // Process get requests sent by the client Public void doget (httpservletrequest request, httpservletresponse response) Throws servletexception, ioexception { Response. setcontenttype ("text/html; charset = gb2312"); // This statement specifies the content format and character encoding used to send to the client. Printwriter out = response. getwriter (); Out. println ("Hello! "); // Use the printwriter object method to send data to the client Out. Close (); } // Process the POST request sent by the client Public void dopost (httpservletrequest request, httpservletresponse response) Throws servletexception, ioexception { Doget (request, response); // This statement is used to call the doget () method for processing when the client sends a POST request. } } |