servlet中的hello world无法正常工作

时间:2013-02-10 04:39:13

标签: tomcat servlets

我现在试着在eclipse中运行一个简单的hello world程序,使用servlet但是没有工作,看了几个教程但没有运气,如果有人可以请看看它

我的错误和项目资源管理器

my error and project explorer

我的servlet类

                 /**
    * Servlet implementation class HelloWorldServlet
         */
   public class HelloWorldServlet extends HttpServlet {
private static final long serialVersionUID = 1L;

/**
 * @see HttpServlet#HttpServlet()
 */
public HelloWorldServlet() {
    super();
    // TODO Auto-generated constructor stub
}

/**
 * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
 */
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
    PrintWriter out = response.getWriter();
    out.println("Hello World");
}

/**
 * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
 */
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
    // TODO Auto-generated method stub
}

我的web.xml

           <?xml version="1.0" encoding="UTF-8"?>
        <web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"       xmlns="http://java.sun.com/xml/ns/javaee" xmlns:web="http://java.sun.com/xml/ns/javaee/web-   app_2_5.xsd" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee               http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" id="WebApp_ID" version="2.5">
         <display-name>FirstServlet</display-name>
       <welcome-file-list>
       <welcome-file>index.html</welcome-file>
      <welcome-file>index.htm</welcome-file>
        <welcome-file>index.jsp</welcome-file>
      <welcome-file>default.html</welcome-file>
     <welcome-file>default.htm</welcome-file>
        <welcome-file>default.jsp</welcome-file>
    </welcome-file-list>
     <servlet>
      <description></description>
     <display-name>HelloWorldServlet</display-name>
     <servlet-name>HelloWorldServlet</servlet-name>
    <servlet-class>com.theopentutorials.servlets.HelloWorldServlet</servlet-class>
    </servlet>
   <servlet-mapping>
      <servlet-name>HelloWorldServlet</servlet-name>
    <url-pattern>/HelloWorldServlet</url-pattern>
     </servlet-mapping>
    </web-app>

1 个答案:

答案 0 :(得分:0)

删除bin目录并重新编译项目。 还要检查新生成的类是否放在bin