如何在eclipse中运行servlet [英] How to run servlets in eclipse

查看:246
本文介绍了如何在eclipse中运行servlet的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是eclipse环境的新手。我下载了eclipse helios和tomcat 6.我正确配置它们。现在我的工作是为一些登录形式创建servlet。我已经给了我公司一些现有的servlet文件。我只需要修改它。有人能告诉我如何运行我现有的servlet文件吗?如何连接文件与我的mysql表?

i am new to eclipse environment. I downloaded eclipse helios and tomcat 6. I configured them properly. Now my job is to create servlet for some sign in form. I have been given some existing servlet file from my company. I just need to modify it. Could anybody tell me how to run my existing servlet file? How to connect the file with my mysql table?

推荐答案

创建java web应用程序的步骤:

1.创建新的动态网络项目

2.将现有servlet文件复制到src文件夹

3.在WebContent / WEB-INF文件夹中创建 web.xml 文件

4.配置 web.xml ,例如:

Steps to create java web application:
1.Create new Dynamic Web Project
2.Copy existing servlet file to src folder
3.Create web.xml file in WebContent/WEB-INF folder
4.Configure web.xml, for example:

<?xml version="1.0" encoding="UTF-8"?>
<web-app 
        xmlns="http://java.sun.ru/xml/ns/javaee" 
        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
        xsi:schemaLocation="http://java.sun.ru/xml/ns/javaee http://java.sun.ru/xml/ns/javaee/web-app_2_5.xsd" 
        version="2.5">
 <servlet>
    <servlet-name>hello</servlet-name>
    <servlet-class>test.HelloServlet</servlet-class>
  </servlet>

  <servlet-mapping>
    <servlet-name>hello</servlet-name>
    <url-pattern>/hello</url-pattern>
  </servlet-mapping>
</web-app>

使用您的servlet类替换 test.HelloServlet ,servlet名称也可以替换

5.在Eclipse中打开服务器视图,使用上下文菜单添加新的Tomcat服务器,发布项目并运行服务器。

replace test.HelloServlet by your servlet class, servlet name also may be replaced
5.Open Server view in Eclipse, add new Tomcat Server using context menu, publish the project and run server.

这篇关于如何在eclipse中运行servlet的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆