Javax.mail is analysed. The servlet. Servlet the ServletContext interface

  • 2020-04-01 02:05:03
  • OfStack

1. The ServletConfig interface is used to describe the configuration information of the Servlet itself. The ServletContext interface is used to describe information about the application (a Context configuration in server.xml, that is, a virtual directory).

2.Servlet configuration initialization parameters, such as:

<servlet>
 <servlet-name>XXX</servlet-name>
 <servlet-class>Xxx</servlet-class>
 <init-param>
  <param-name>yyy</param-name>
  <param-value>xxx</param-value>
 </init-param>
</servlet>

The initialization parameters, can pass this. GetServletConfig. GetInitParameter ().
The javax.servlet.servlet interface is the basic interface of servlets, which all defined servlets must implement. Javax.mail. Servlet. GenericServlet is a base class implements this excuse. HttpServlet simply inherits the GenericServlet class. GenericServlet implementation ServletConfig interface, so in the HttpServlet can directly call the ServletConfig method, such as HttpServlet. GetInitParameter (), the HttpServlet. GetServletName (); HttpServlet. GetServletContext () method and so on, and don't have to use this. GetServletConfig. GetInitParameter () and so on.

4. Init method of Servlet:
The init method of the javax.servlet.servlet interface is parameterized.init (ServletConfig) method. After the GeneralServlet class implements the Servlet interface, there is a call to the parameterless init() method for extension after the basic functionality is implemented in the init(ServletConfig) method. So in our inherited HttpServlet method, we generally override the init method with no arguments.

5. Service method of Servlet:
This method is the main method of servlets. All requests are handed over to this method for execution. In HttpServlet, the function of service method is to send the request to doPost,doGet and other methods for processing according to the type of request. So in HttpServlet, you only need to override doPost,doGet, etc., if you override the doService method, doPost,doGet method will not work.

Related articles: