1. Create class: Com.itheima.servlet HelloServlet
Edit Helloservlet.java Class
Editing completed, 5 new methods added.
A, the configuration file implements the Servlet interface.
Move the service method in the 5 methods to the front ( when the client accesses, the background prints the helloservlet ... )。
B. Configure the servlet to tell the server servlet service.
Configuration file Web. Xml.
<!--to Tomcat , where the servletname is HelloServlet, and the specific path is com.itheima.servlet.HelloServlet--
<servlet>
<servlet-name>HelloServlet</servlet-name>
<servlet-class>com.itheima.servlet.HelloServlet</servlet-class>
</servlet>
<!--register the servlet mappings. servlet-name corresponds to the above specific servlet service,URL-pattern: Client Access Path--
<servlet-mapping>
<servlet-name>HelloServlet</servlet-name>
<url-pattern>/ABC</url-pattern>
</servlet-mapping>
Start error due to incorrect configuration of Url-pattern.
Severity: A child container failed during start
java.util.concurrent.ExecutionException: org.apache.catalina.LifecycleException: Failed to start component [Standardengine[catalina]. Standardhost[localhost]. Standardcontext[/helloservlet]]
At Java.util.concurrent.FutureTask.report (Unknown Source)
Access the test.
2. Inheritance Test
Creates a class that inherits the service method of the parent class.
Public class HelloServlet02 extends httpservlet{
@Override
protected void doget (httpservletrequest req, HttpServletResponse resp) throws Servletexception, IOException {
System. out. println ("HelloServlet ...");
}
}
Configure the Web. xml file.
Test the other two methods.
The service method needs to be commented.
Eclipse Create servlet