Servlet & Jsp

What is the servlet

servlet is a technology used to develop dynamic web resources, small Java program can run in a Web server, sometimes called applets on the server side. servlet may receive and respond to requests from the Web client through the HTTP protocol.
servlet syntax is the same with JavaSE JavaSE and can be used in the API, in order to create a dynamic resource can be divided into the following two steps:

  1. Write a Java class that implements javax.servlet.Servlet interface that the packet servlet-api.jar
  2. The Java class deployment in the web server

web browser response process

 

 

servlet execution process

 

 

 Servlet life cycle can be divided into four stages, namely loading class and create an instance of the stage, the initialization phase (call the init method), the service stage (call service method) and examples of the destruction stage (call distroy method)

 

servlet architecture

 


servlet hierarchy and description of commonly used classes:

  1. Of GenericServlet: abstract class that defines a common, independent of the underlying protocol Servlet.
  2. Most Servlet is achieved by extending from GenericServlet or HttpServlet class.
  3. ServletConfig transmitted by the Servlet interface defines Servlet container during initialization to obtain configuration information to the Servlet object.
  4. ServletRequest HttpServletRequest interface extends the interface to provide information to the HTTP request HTTP Servlet.
  5. HttpServlet is a subclass of GenericServlet.
  6. GenericServlet is an abstract class, subclass must be given to instantiate. It gives some servlet skeleton design, the definition of the servlet life cycle, and some get the name, configuration, initialization parameters of the method, and its design is the application layer protocol-independent, which means that you may use non-http protocol Realize it.
  7. HttpServlet is a subclass, of course, has all the characteristics of GenericServlet, also added doGet, doPost, doDelete, doPut, doTrace the like corresponding to the process request command to the http protocol in response to the process.
  8. Generally do not have special needs, wrote the Servlet both extend HttpServlet.

 

Reproduced in: https: //www.cnblogs.com/lucky1024/p/11055585.html

Guess you like

Origin blog.csdn.net/weixin_33845881/article/details/93758075