SPRINGMVC Source code reading servlet Part < A >servlet part of the explanation

Source: Internet
Author: User

The concept of "one" servlet

"Two" a simple servlet demo

Part I: Configuration of Web. xml

<!--create a native selevt to re-learn the servlet -<servlet>   <Servlet-name>Sxfservlet</Servlet-name>   <Servlet-class>Com.yeepay.nobank.sxfservlet.ImgStudyServlet</Servlet-class>      <Init-param>             <!--init parameter -             <Param-name>MyName</Param-name>             <Param-value>My name is Shangxiaofei</Param-value>       </Init-param>       <!--the timing of the Init method invocation of the servlet, when set to negative or not set, is called when the servlet is first used -       <Load-on-startup>1</Load-on-startup></servlet><servlet-mapping>   <Servlet-name>Sxfservlet</Servlet-name>   <Url-pattern>/sxf/*</Url-pattern></servlet-mapping>
View Code

Part II: Source Code of Imgstudyservlet

 PackageCom.yeepay.nobank.sxfservlet;Importjava.io.IOException;ImportJavax.servlet.ServletConfig;Importjavax.servlet.ServletException;ImportJavax.servlet.http.HttpServlet;Importjavax.servlet.http.HttpServletRequest;ImportJavax.servlet.http.HttpServletResponse;/*** Servlet's *@authorShangxiaofei **/ Public classImgstudyservletextendshttpservlet{/*** called only once throughout the servlet lifecycle for loading configuration information and doing some initialization actions*/@Override Public voidInit (servletconfig config)throwsservletexception {System.out.println ("Imgstudyservlet.init () call the first Init method to start! "); Super. init (config); String mynamestrstring=config.getinitparameter ("MyName"); System.out.println ("Imgstudyservlet.init ()" +mynamestrstring); System.out.println ("Imgstudyservlet.init () call the first Init method end! "); }    /*** When the client is a GET request, call the method*/@Overrideprotected voiddoget (httpservletrequest req, HttpServletResponse resp)throwsservletexception, IOException {String param1=req.getparameter ("param"); System.out.println ("Imgstudyservlet.doget ([param]===>)" +param1); }    /*** When the client is a POST request, call the method*/@Overrideprotected voidDoPost (httpservletrequest req, HttpServletResponse resp)throwsservletexception, IOException {String param1=req.getparameter ("param"); System.out.println ("Imgstudyservlet.dopost ([param]===>)" +param1); }    /*** When the servlet is destroyed, call the method and do some cleanup work*/@Override Public voiddestroy () {System.out.println ("Imgstudyservlet.destroy" ([Destroy ...]) ".... ...)"); }            }
View Code

Part III: Talk about Web project packaging, start the Tomcat container. Tomcat's boot log print startup message contains

Part III: Sending requests to Web projects Http://localhost:8080/nobankcard-web/sxf/s?param=tiantianxiangshanghaohaoxuexi,tomcat print logs

Part IV: When Tomcat is turned off, tomcat prints the log

SPRINGMVC Source code reading servlet Part < A >servlet part of the explanation

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.