Download the Tomcat service first to run Java programs similar to IIS in Windows
: tomcat.apache.org, it is best to download the zip compression version, after decompression can be used directly. Such as:
The following creates a "Dynamic Web project", such as:
Create a good directory such as:
Add a servlet to the project. Steps: Right-click on "src" > New >servlet, fill in the Java Packages (package name) and class name (class name) Two, then click Next to finish.
If you create a servlet page HttpServletRequest error, most of the missing Servlet-api.jar package, you can find it from the Tomcat Lib folder and copy it to the Lib folder under Web-int in the project, as
The code in Demo.java is as follows (after removing the useless code)
Package Test;import Java.io.ioexception;import Javax.servlet.servletexception;import Javax.servlet.annotation.webservlet;import Javax.servlet.http.httpservlet;import Javax.servlet.http.httpservletrequest;import javax.servlet.http.httpservletresponse;/* * @ Webservlet is the URL address of the servlet * do not need to go to the Web. Xml to configure the servlet information * */@WebServlet ("/demo.html") public class Demo extends HttpServlet {private static final long serialversionuid = 1l;protected void doget (HttpServletRequest request, HttpServlet Response Response) throws Servletexception, IOException {response.getoutputstream (). Write ("Hello". GetBytes ());} protected void DoPost (HttpServletRequest request, httpservletresponse response) throws Servletexception, IOException { Doget (request, Response);}}
Post-run interface such as
Java Create Web Project