1.  创建项目:Dynamic Web Project,名为 "First"

1) Goto File -> New -> Dynamic Web Project

Eclipse创建Servlet并在html调用

2) Give a Name to your Project and click Next

Eclipse创建Servlet并在html调用

Eclipse创建Servlet并在html调用

3) Check Generate web.xml Deployment Descriptor and click Finish

Eclipse创建Servlet并在html调用

4) Now, the complete directory structure of your Project will be automatically created by Eclipse IDE.

Eclipse创建Servlet并在html调用

2. 创建Servlet,名为“MyServlet”

1) Click on First project, go to Java Resources -> src. Right click on src select New -> Servlet

Eclipse创建Servlet并在html调用

2) Give Servlet class name and click Next

Eclipse创建Servlet并在html调用

3) Give your Servlet class a Nma of your choice.(use default here) 

Eclipse创建Servlet并在html调用

4) Leave everything else to default and click Finish

Eclipse创建Servlet并在html调用

5) Now your Servlet is created, write some code inside it. You can take reference from the code in the picture below.

Eclipse创建Servlet并在html调用

or like below

Eclipse创建Servlet并在html调用

3. 添加jar文件到项目中(servlet-apt.jar)

1)  Click on Libraries, right click on Web App Librariesselect Build Path -> Configure Build Path

Eclipse创建Servlet并在html调用

2) Click on Add External JARs

Eclipse创建Servlet并在html调用

3) Select servlet-api.jar from Apache Tomcat Directory, click "Open" button, this JAR is now added to your project's build path, click OK to finish

Eclipse创建Servlet并在html调用

4.在WebContent目录下创建index.html

set form-action-name as "test"

Eclipse创建Servlet并在html调用

5. 用web.xml配置Servlet

Eclipse创建Servlet并在html调用

6. 启动服务器,开始测试

Eclipse创建Servlet并在html调用

Eclipse创建Servlet并在html调用

1.  创建项目:Dynamic Web Project,名为 "First"

1) Goto File -> New -> Dynamic Web Project

Eclipse创建Servlet并在html调用

2) Give a Name to your Project and click Next

Eclipse创建Servlet并在html调用

Eclipse创建Servlet并在html调用

3) Check Generate web.xml Deployment Descriptor and click Finish

Eclipse创建Servlet并在html调用

4) Now, the complete directory structure of your Project will be automatically created by Eclipse IDE.

Eclipse创建Servlet并在html调用

2. 创建Servlet,名为“MyServlet”

1) Click on First project, go to Java Resources -> src. Right click on src select New -> Servlet

Eclipse创建Servlet并在html调用

2) Give Servlet class name and click Next

Eclipse创建Servlet并在html调用

3) Give your Servlet class a Nma of your choice.(use default here) 

Eclipse创建Servlet并在html调用

4) Leave everything else to default and click Finish

Eclipse创建Servlet并在html调用

5) Now your Servlet is created, write some code inside it. You can take reference from the code in the picture below.

Eclipse创建Servlet并在html调用

or like below

Eclipse创建Servlet并在html调用

3. 添加jar文件到项目中(servlet-apt.jar)

1)  Click on Libraries, right click on Web App Librariesselect Build Path -> Configure Build Path

Eclipse创建Servlet并在html调用

2) Click on Add External JARs

Eclipse创建Servlet并在html调用

3) Select servlet-api.jar from Apache Tomcat Directory, click "Open" button, this JAR is now added to your project's build path, click OK to finish

Eclipse创建Servlet并在html调用

4.在WebContent目录下创建index.html

set form-action-name as "test"

Eclipse创建Servlet并在html调用

5. 用web.xml配置Servlet

Eclipse创建Servlet并在html调用

6. 启动服务器,开始测试

Eclipse创建Servlet并在html调用

Eclipse创建Servlet并在html调用

相关文章: