The First Servlet Project by Eclipse -- Hello, World!

按:文中所提到的 servlet 是通过 Eclipse 自动生成的,是 extends HttpServlet 的,事实上,Servlet 接口下,还有 GenericServlet 类可以扩展。——2010.06.22

Every language or new technology's tutorial begins with "hello, world", this does. To use Eclipse IDE for Java EE Developers, it can fast create a servlet project! I recorded a video of the whole procedure of creating, building, and running a HelloWorld servlet project in the Eclipse:

Sorry that it's not clear coz the bad network, and very blur in full sreen model. The clear version is attached.

Anyhow, the video shows that using the Eclipse to build a servlet project is too simply. All the steps are:

1. Build a blank dynamic project.

Click File -> New -> Project... to open the New Project dialog, choose Web - Dynamic Web Project, click next and create a project named helloworldservlet.

2. Create a servlet class and rewrite its doGet method.

Expand the tree of helloworldservlet in Package Explorer component, right click src folder, to new a servlet followed by it guild. Then rewrite the doGet method.

3. Modify web.xml.

The <servlet> and <servlet-mapping> tags are generated automatically while servelet classes are being creating. Just to modify the <welcome-list> in order to open an existed URI when the project is running first time.

4. Run the project in Tomcat.

後记:构建一个可使用的最简单的 servlet 的完整步骤

1. 扩展 HttpServlet 并重写其中的 doGet 方法,其余方法删除,并在 doGet 方法中得到 java.writer.PrintWriter 对象,调用 print 方法,打印 html 内容。

2. 配置 {project home}/WEB-INF/web.xml 文件,添加 servlet 对应的信息。如果使用 Servlet 3.0+ 的 Annotation,在具体的 Servlet 实现类中加上相应的 Annotation 即可,无需再配置 web.xml

3. 发布,并访问。


  1. Source code of this demo is attached as on this page, and the youtube video link is here.
  2. Form 中使用 servlet 时可能遇到的路径问题及解决