Java Web Note servlet (1)

Source: Internet
Author: User

When learning the servlet today, the Web page effect displayed by the browser is different from what is expected, looking closely for the found real <! Doctype> the issue of the statement, as follows:

The code is as follows:

 PackageSecondservlet;Importjava.io.IOException;ImportJava.io.PrintWriter;Importjavax.servlet.ServletException;ImportJavax.servlet.http.HttpServlet;Importjavax.servlet.http.HttpServletRequest;ImportJavax.servlet.http.HttpServletResponse; Public classSecondservletextendsHttpServlet {/**     *      */    Private Static Final LongSerialversionuid = 87826386236823L; /*** Execute this function when accessing a page in Get mode * Executing the Doget method executes the Getlastmodified method, and if the browser discovers that the Getlastmodified method returns * The same value as the last returned value, the document is considered not to be updated. The browser takes the cache without executing the Doget method * If the Getlastmodified method returns-1, it is considered to be a constant update and always executes the function*/     Public voiddoget (httpservletrequest request, httpservletresponse response)throwsservletexception, IOException { This. log ("Execute Doget Method ...");  This. Execute (Request, response); }    /*** This function is executed when the page is accessed by post. Getlastmodified method not executed before execution **/     Public voidDoPost (httpservletrequest request, httpservletresponse response)throwsservletexception, IOException { This. log ("Execute Dopost Method ...");  This. Execute (Request, response); } @Override Public Longgetlastmodified (HttpServletRequest request) { This. log ("Execute Getlastmodified Method ..."); return0; }             Public voidExecute (httpservletrequest request, httpservletresponse response)throwsioexception{response.setcharacterencoding ("UTF-8"); Request.setcharacterencoding ("UTF-8"); String RequestUri=Request.getrequesturi (); String Method=Request.getmethod (); String param= Request.getparameter ("param"); Response.setcontenttype ("Text/html"); PrintWriter out=Response.getwriter (); Out.println ("<! DOCTYPE HTML public \ "-//W3C//DTD HTML 4.01 transitional//en\" > ");//out.println ("<! DOCTYPE html> ");Out.println ("<HTML>"); Out.println ("); Out.println ("<body>"); Out.println ("+ Method +" to access the page. The Param parameters are: "+ param +" <br/> "); Out.println ("<form action=" + RequestUri + "' method= ' get ' > <input type= ' text ' name= ' param ' value= ' param string ' ><in Put type= ' submit ' value= ' Get way Query page Requestservlet ' ></form> '); Out.println ("<form action=" + RequestUri + "' method= ' post ' > <input type= ' text ' name= ' param ' value= ' param string ' ><i Nput type= ' Submit ' value= ' post to page Requestservlet ' ></form> '); Out.println ("<script>document.write (' This page last updated: ' + document.lastmodified + ' <br/> '); </script> "); Out.println ("<script>document.write (' this page URL: ' + location + ' <br/> '); </script> "); Out.println ("</body>"); Out.println ("</HTML>");        Out.flush ();            Out.close (); }}

Java Web Note servlet (1)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.