When most people are new to using Eclipse to develop the Web, there are always problems with Eclipse setup and configuration, especially configuration problems

If you do, you’ll be crying at the door. Let me walk you through the process of setting up the servlet and XML configuration

Step 1: Configure the Tomcat environment for Eclipse

 

Open the Eclipse menu Window -> Preferences to locate the Runtime Enviroments under Server

 

Step 2: Select the Tomcat version. V8.0 is selected because the local environment is 8.0

 

Check the Create a New Local Server check box and click Next

Step 3: Select the Tomcat installation directory and running environment. Here, I choose JDK 1.8.0_45 and click Finish

Step 4: Open the Servers TAB. You can see that one of the Servers is stopped

Step 5: Configure Server parameters. Double-click Tomcat V8.0 Server at localhost to open the configuration page

The three properties circled in the figure mean 1. Use workspace as publishing path 2. Use the Tomcat installation path as the release path. 3

Define the path as the publishing path. Deploy Path sets the publishing subdirectory and sets the Webapps consistent with Tomcat

In this way, tomcat management applications can be accessed at the same time as applications are published. Save and exit to start building the first Servlet application

Step 6: Set up a website project

Step 7: Enter the project name and related attributes

Step 8: Click Next. The default source path does not need to be modified. Click Next to select web. XML and set

After the update, the web. XML configuration file is automatically written back. Click Finish. Only this project has been created

Step 9: Create the associated Class file

Step 10: The class inherits the GenericServlet class and implements the unimplemented methods, typing code

 

package com.itneima;

import java.io.*;
import javax.servlet.*;
import javax.servlet.http.*;

public class helloServlet extends HttpServlet{
	public void doGet(HttpServletRequest request, HttpServletResponse response)
		throws IOException, ServletException
		{
			response.setContentType("text/html; charset=gb2312");
			PrintWriter out = response.getWriter();
			
			out.println("<html>");
			out.println("<head>");
			out.println("<title>HelloWorld</title>");
			out.println("</head>");
			out.println("<body bgcolor=\"white\">");
			out.println("<hr>");
			out.println("HelloWorld");
			out.println("Hello! The world");
			out.println("</body></html>");
		}
	
	public void doPost(HttpServletRequest request, HttpServletResponse response)
		throws IOException, ServletException
		{ doGet(request, response); }}Copy the code

Import related packages at the same time

 



Step 11: Create servlets in your project

Step 12: Select the class file you just created helloServlet and click Next to modify the URL mapping path instead of using the default

Change the helloServlet to Hello and click Finish

Step 13: Open the web. XML file in the WebContent directory to check whether the node information of <servlet> and <servlet-mapping> is correct

Step 14: Finally open helloservlet. Java and select Run on Server

Finally see the running effect, so far configuration and test complete!