Unlike MyEclipse, web projects made in Eclipse do not support publishing projects to the web server by default, and will be published to a directory in the workspace. Therefore, it is impossible to start Tomcat externally to run the web project. Only by opening Eclipse Only the server can run the web project. Therefore, Eclipse needs to be modified to publish the completed project to the Tomcat server and to the Webapps folder on the server. This article introduces two methods;
The first method:
1. Modify the configuration of Tomcat under Servers:
Under show view―>servers, find the tomcat that needs to be modified ―>right-click to complete the following steps :
①Stop the Tomcat server in eclipse (stop)
②Delete the project deployed in this container (add and remove)
③Clear the data related to the container (clean)
④Open the tomcat modification interface (open)
⑤ Find servers location and select the second one (User tomcat Installation)
⑥Modify deploy path to webapps
⑦Save Close
It should be noted that ①②③ must be operated, otherwise the following steps will be grayed out and cannot be operated.
The modified image is as follows:
2. Verify whether the modification is successful:
1. Create a Dynamic Web Project through Eclipse;
2. Add an index.html page;
<body>hello peace</body>
3. Right-click in WebContent to select New-->Other-->Web-->Servlet:
The configuration is as follows: com.rlovep.Hello.Hello.java
Please note that my servlet is 3.0 or above, you can use annotations: no need to modify web.xml;
@WebServlet("/Hello")//Annotation url: /Hellopublic class Hello extends HttpServlet { private static final long serialVersionUID = 1L; protected void doGet(Htt pServletRequest request, HttpServletResponse response) throws ServletException, IOException { PrintWriter out = response.getWriter( ); out.println("hello peace");}}
4. Right-click (add and remove) to add the project to Tomcat:
5. You can see your project folder under the Webapps folder on the server; (such as my HttpSer)
6. When running Tomcat, you can see the following figure:
Home page: http://localhost:8080/HttpSer/
Hello page (servlet): http://localhost:8080/HttpSer/Hello
The second method: through tomcatPlugin plugin
1. Download the plugin and unzip it into the plugins directory under Eclipse and restart it. You will see 3 kittens and configure the tomcat home in Window->perferences->tomcat as the tomcat directory application.
2. The tomcat property configuration of the project is as follows: Main modification: Tick Is a Tomcat Project; modify the Context name to the name you want
Right-click to project run, run server; run the program to get the same result as above.
The above is the entire process of Eclipse deploying dynamic web projects. I hope it will be helpful to everyone's learning.