If Tomcat is not configured in the system, refer to "How to configure Tomcat environment variables under Windows".
1. Create a new Web project item. As follows:
The effect is as follows:
2. Write a Java class that implements the Servlet interface or inherits HttpServlet
1 Package Com.cnblogs.daliu_it.web;2 3 import java.io.IOException;4 import Java.io.PrintWriter;5 import javax.servlet.ServletException;6 import Javax.servlet.http.HttpServlet;7 import javax.servlet.http.HttpServletRequest;8 import Javax.servlet.http.HttpServletResponse;9 Ten Public classHelloWorld extends HttpServlet { One protected voidService (HttpServletRequest req, HttpServletResponse resp) A throws Servletexception, IOException { -Resp.setcontenttype ("text/html"); -PrintWriter out=Resp.getwriter (); the out. Write (""); - out. Close (); - } -}View Code
3. Modify the Web. xml file.
1<?xml version="1.0"encoding="UTF-8"?>2<web-app version="2.5"xmlns="Http://java.sun.com/xml/ns/javaee"3Xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"4xsi:schemalocation="Http://java.sun.com/xml/ns/javaee5http//java.sun.com/xml/ns/javaee/web-app_2_5.xsd ">6<display-name></display-name>7<servlet>8<servlet-name>HelloWorld</servlet-name>9<servlet-class>com.cnblogs.daliu_it.web.helloworld</servlet-class>Ten</servlet> One A<servlet-mapping> -<servlet-name>HelloWorld</servlet-name> -<url-pattern>/HelloWorld</url-pattern> the</servlet-mapping> -<welcome-file-list> -<welcome-file>index.jsp</welcome-file> -</welcome-file-list> +</web-app>
View Code
4. Deploying to Tomcat
(1) Configuring the server
(2) Select the extracted directory for Tomcat 7.0.
Click Apply.
Click OK.
5. Deploy to Tomcat
Click Finish. Then OK.
6. Start Tomcat,
7. Access the servlet.
Http://localhost:8080/firstweb/HelloWorld
Original Daliu_it
Blog Source: http://www.cnblogs.com/liuhongfeng/p/4178424.html
How to deploy a project to Tomcat in MyEclipse