Eclipse Create servlet

Source: Internet
Author: User

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

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.