1. Start with "P" of JSP, which page can be executed? Impossible! It will certainly be an object, that is, jsp is an object, but who will make it new; what is its class?
The first problem: tomcat is a new client. Yes, jsp must comply with certain writing specifications. This is to make tomcat better, or tomcat is a jsp Container.
The second question: <% = this instanceof HttpServlet %> is the answer.
2. "True" is the answer to the second question, indicating that JSP is an object of the HttpServlet subclass, which is a simplified version. Now we need to customize a class to do the same work as JSP:
Class MyServlet extends HttpServlet {
Public void deGet (HttpServletRequest req, HttpServletResponse resp ){
// Put the java code in jsp here: Where are the objects ?)
}
}
3. How to run it?
If we run it ourselves, we must do this:
HttpServlet MS = new Myservlet ();
Ms .. doGet (req, resp );
But how are two object arguments passed?
We hope that it runs like jsp, that is, it should meet the following four things for short ):
1) Automatic execution of each access
2) Automatic instantiation
3) The method is automatically called, and the real parameters passed by the method are also instantiated.
4) There should be a unique url to ensure it can be accessed.
All of this should be done by tomcat.
But what is the current situation ?...... We only have one MyServlet class. We need to do more to let Tomcat know about this class and do the "four things ".
4. How can we solve the "four things?
The WEB-INF/web. xml under the project is a magic file that can be addressed here together:
<! -Define a servlet here. tomcat can know it->
<Sevlet>
<Sevlet-name> name </servlet-name>
<Sevlet-class> package name. class Name </servlet-class>
</Sevlet>
<! -Specify the url here->
<Servlet-mapping>
<Sevlet-name> name </servlet-name>
<Url-parten>/url </url-parttern>
</Sevlet-mapping>
In this way, we can use http: // ip: port/project/url in the browser to access and execute the program in doGet.