Eclipse Tomcat8 Write a servlet

Source: Internet
Author: User

Eclipse4.5 (Mars) for Java EE Edition

TOMCAT8 installation, setting Java_home environment variables

Establish Dynamic Web project, which targets the TOMCAT8 server.

Note: When creating a project, select Generate Web. xml

-------------------------------------

Right-click on Project, New, servlet

Name: Hello, inherit HttpServlet, package name: Gyh.serv

To modify the Java file, add the Doget method:

Response.getwriter (). Write ("Simple Hello");

Save.

Modify the web.xml,<web-app> tag to add information:

  <servlet>      <Servlet-name>Haha</Servlet-name>      <Servlet-class>Gyh.serv.Hello</Servlet-class>  </servlet>  <servlet-mapping>      <Servlet-name>Haha</Servlet-name>      <Url-pattern>/hhh</Url-pattern>  </servlet-mapping>

What it does: give the Hello class an individual name and associate the alias to a URL address.

Java file, right-click, run, run on the server, you can see the effect of the browser output.

---------------------------

Web project, right-click, Export,war file,

Select the items you want to export, and where the war files need to be stored. is automatically packaged as a war file. This is the war package.

The war file is copied to Tomcat8 's WebApps directory, even if it is published.

Start Tomcat8 on the console (with Startup.bat, it's okay with Eclipse)

In the browser, enter: Http://127.0.0.1:8080/web_test_2/hhh

Should be able to see the effect.

Stop the server (shutdown.bat), delete the war package under WebApps, and go back to the original point.

Eclipse Tomcat8 Write a 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.