Li Wu:
Learn to think more, honouring teachers save Thanksgiving. Leaf See Root 321, rivers with one.
Meekness Conscience Lord, willing to do without regrets to the most bitter. Reading exercise strong body and mind, Prudential advised and the line and cherish.
Javaee:7
javase:1.8
jstl:1.2.2
Server:tomcat 8.5
Explorer:firefox
Os:windows7 x64
Ide:myeclipse
Xml
<?xml version= "1.0" encoding= "UTF-8"? ><web-app xmlns:xsi= "Http://www.w3.org/2001/XMLSchema-instance" xmlns= "Http://xmlns.jcp.org/xml/ns/javaee" xsi:schemalocation= "Http://xmlns.jcp.org/xml/ns/javaee/http Xmlns.jcp.org/xml/ns/javaee/web-app_3_1.xsd "id=" webapp_id "version=" 3.1 "><servlet><servlet-name> mygenericservlet</servlet-name><servlet-class>jizuiku.web.servlet.mygenericservlet</ servlet-class><!--perform this class of--><init-param><param-name>minnum</param-name>< param-value>10</param-value></init-param><init-param><param-name>maxnum</ Param-name><param-value>100</param-value></init-param></servlet><servlet-mapping ><servlet-name>myGenericServlet</servlet-name> <!--two name corresponding to the good--><url-pattern>/ mygenericservletdemo</url-pattern><!--Access is this path--></servlet-mapping></web-app>
Code that inherits the class of Genericservlet
Package Jizuiku.web.servlet;import Java.io.ioexception;import Javax.servlet.genericservlet;import Javax.servlet.servletexception;import Javax.servlet.servletrequest;import javax.servlet.servletresponse;/** * * * @author to the bitter * @version V17.10.20 */public class Mygenericservlet extends genericservlet{/** * */private S Tatic final Long serialversionuid = 1L; @Overridepublic void Service (ServletRequest servletrequest, Servletresponse Servletresponse) throws Servletexception, IOException {System.out.println ("perform service () ..."); According to the source code can be introduced, the method to be rewritten must be init () @Overridepublic void Init () throws Servletexception {//TODO auto-generated method Stubsyste M.out.println ("Hello, execute Initialization program");} @Overridepublic void Destroy () {//TODO auto-generated method StubSystem.out.println ("Execute Destroy () ...");}}
Effect
When the browser accesses the specified page once, the console output information changes as follows
Extended
Why would you want to override the parameterless init () method? Please look at the source code
/** * Called by the servlet container to indicate to a servlet, the servlet * is being placed into service. See {@link servlet#init}. * <p> * This implementation stores the {@link ServletConfig} object it receives * from the servlet container For later use. When overriding this form of * The method, call <code>super.init (config) </code>. * * @param config * The <code>ServletConfig</code> object that contains * Configuration information for this servlet * @exception servletexception * If a exception occurs that int Errupts the servlet s * normal operation * @see unavailableexception */@Override public void init (ServletConfig config) throws servletexception { this.config = config; This.init (); }
A brief introduction to Serialversionuid
website: http://www.cnblogs.com/btdxqz/p/6806372.html
Learning resources: Itcast and Itheima Video library. If you have public resources, can share to me, with your resources to learn also can.
Blog post is to watch the video, into thinking written. It's good that the teacher speaks well. Blog bad, is to give the most bitter not serious.
Javaweb Basic Inheritance Genericservlet Simple example