SERVLET API - GenericServlet class brief description

zhaozj2021-02-16  52

GenericServlet Class: Public Abstract Class GenericServlet Extends Java.lang.Object Implements Servlet, ServletConfig, Java.io.Serializable

Java.lang.Object | - javax.servlet.GenericServlet Parent Class / Interface: java.io.serializable interface, servlet interface, servletconfig interface subclasses: httpservlet class

This class defines a normal, dependent on the protocol, if you want to write an HTTP Servlet for the web, extend the HPPTSERVLET. A servlet can expand the GenericServlet class directly, however, the subclass of a specified protocol (such as httpservlet) is more common. The genericServlet class makes it easier to write servlets. It provides a general version of lifecycle method: ININ (), Destroy () and methods from servletconfig interfaces. The GenericServlet class also implements the log () method, which is a method defined in the servletContext class. Since GenericServlet is an abstract class, you must extend this class, you must implement all abstraction methods of this class.

The Destory () method effect is the same as the servlet.destory () method, slightly.

GetInitParameter () method Overview: Public Java.lang.String GetInitParameter (java.lang.string name) Returns a string containing the value of the initialization variable, returns null if the variable does not exist, the method gets a name variable from the servletConfig variable from the servlet. Value.

GetInitParameterNames () Method Overview: Public Java.util.EnuMeration GetInitParameterNames () This method returns an enumeration function that contains all initialization variables. If there is no initialization variable, return an empty enumeration function.

GetServletConfig () Method: Public servletconfig getServletConfig () returns a servletConfig object GetServletContext () method is the same as servletconfig.getServletContext (), slightly.

GetServletInfo () Method Overview: Public Java.lang.String GetServletInfo () This method comes from the servlet interface to overwrite the method to generate meaningful information. (, Such as version number, copyright, author, etc.) INIT (ServletConfig config) method Overview: public void init (servletconfig config) Throws servletexception This method comes from the servlet interface, override the method, must call Super.init (config)

INIT () Method Overview: Public Void Init () THROWS ServleTexception This method is overloaded with the servlet.init (servletconfig config) method without calling Super.init (config). The servletconfig object can still be obtained by calling the GetServletConfig () method.

Log (java.lang.string msg) method Overview: Public void log (java.lang.string msg) This method writes the specified information to a log file, see servletContext.log (String). Log (Java.lang.String Message, Java.lang.Throwable T) method Overview: public void log (java.lang.string message, java.lang.throwable t) This method puts interpretive content and throw exception information Write a log file.

Service () method Overview: Public Abstract Void Service (ServletRequest Req, ServletResponse Res) Throws ServletException, java.ioException This method must be called by servlet container to allow servlet to respond to request. See servlet.service (javax.servlet.servletRequest, javax.servlet.servletResponse).

GetServletName (), see servletConfig.getServletName ().

转载请注明原文地址:https://www.9cbs.com/read-20405.html

New Post(0)