无法在JETTY上部署简单的hello world servlet

时间:2013-01-15 21:00:56

标签: servlets jetty

我对Web应用程序完全陌生,并按照本教程创建了一个简单的hello world servlet。

http://www.roseindia.net/servlets/HelloWorld.shtml
http://www.roseindia.net/servlets/directory-structure.shtml
http://www.roseindia.net/servlets/HowToRunAServlet.shtml

不幸的是我无法运行它。我有以下目录结构(servlet类实际上是正确的,在这个快照中只是错误的):

enter image description here

这些文件包含链接中列出的以下代码:

HelloWorld.java

import java.io.*;
import javax.servlet.*;
import javax.servlet.http.*;

public class HelloWorld extends HttpServlet {
    public void doGet(HttpServletRequest request, HttpServletResponse response)
            throws ServletException, IOException {
        response.setContentType("text/html");
        PrintWriter pw = response.getWriter();
        pw.println("<html>");
        pw.println("<head><title>Hello World</title></title>");
        pw.println("<body>");
        pw.println("<h1>Hello World</h1>");
        pw.println("</body></html>");
    }
}

的web.xml

<?xml version="1.0" encoding="ISO-8859-1"?>
<!--<!DOCTYPE web-app
 PUBLIC "-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN"
 "http://java.sun.com/dtd/web-app_2_3.dtd"> -->

<web-app>
 <servlet>
  <servlet-name>Hello</servlet-name>
  <servlet-class>HelloWorld</servlet-class>
 </servlet>
 <servlet-mapping>
 <servlet-name>Hello</servlet-name>
 <url-pattern>/HelloWorld</url-pattern>
 </servlet-mapping>
</web-app>

它被指示像这样调用hello World程序: 本地主机:8080 /你好/你好

但我得到的只是

HTTP错误404

访问/ hello / Hello时出现问题。原因是:

未找到

我的文件结构是

JETTY/webapps/hello/
                web.xml
                WEB-INF/
                   classes/
                       HelloWorld.class
                   lib/

0 个答案:

没有答案