myclipse中建立servlet

首先配置好开发环境eclipse+tomcat+myeclipse,同时你也可以汉化,如果需要了解如何配置,可以参考我的blog上的一篇文章     --eclipse+tomcat+myeclipse配置j2ee开发环境     

http://blog.csdn.net/shenmingya/archive/2007/04/10/1559531.aspx


运行装有插件的eclipse,新建立一个WEB工程,比如名字为example
选择新建立的WEB项目example,右建菜单建立servlet, 输入名字为abc,包名为s,这样myeclipse就会为你自动建立一个servlet,并有相关的代码,你只要在里面添加代码即可.

自动建立的servlet会自动配置web.xml文件,而不用用户自己去修改web.xml,不过还是希望用户对web.xml有所了解.
我们再看看web.xml文件内容为:
<?xml version="1.0" encoding="UTF-8"?>
<web-app version="2.4"
    xmlns="http://java.sun.com/xml/ns/j2ee"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee
    http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd">
  <servlet>
    <description>This is the description of my J2EE component</description>
    <display-name>This is the display name of my J2EE component</display-name>
    <servlet-name>abc</servlet-name>
    <servlet-class>s.abc</servlet-class>
  </servlet>

  <servlet-mapping>
    <servlet-name>abc</servlet-name>
    <url-pattern>/servlet/abc</url-pattern>
  </servlet-mapping>
</web-app>
这样一个简单的sevllet就建立好了,然后进行布置项目(右键项目->myclipse->Add and Remove Project Deployments   选择你的项目,按ADD,再选择tomcat)
启动tomcat

 打开IE,在地址栏中输入:http://localhost:8080/example/servlet/abc,我们就可以在IE中看到如下结果了
This is class s.abc, using the GET method
这就表示servlet运行成功了
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章