HTTP 404尝试运行servlet时出错

时间:2015-04-03 16:01:36

标签: servlets

我正在获取HTTP状态404 - / Servlets_Tutorials / FirstServlet

FirstServlet.java

package com.servlet.learning;    
import java.io.*;    
import javax.servlet.*;
class FirstServlet implements Servlet {
ServletConfig config = null;

    public void init(ServletConfig config) {
        this.config = config;
        System.out.println("servlet is initialized");
    }


    public void service(ServletRequest req, ServletResponse res)
            throws ServletException, IOException {

        res.setContentType("text/html");

        PrintWriter out = res.getWriter();
        out.print("<html><body>");
        out.print("<b>hello simple servlet</b>");
        out.print("</body></html>");

    }


    public void destroy() {
        System.out.println("servlet is destroyed");
    }

    public ServletConfig getServletConfig() {
        return config;
    }

    public String getServletInfo() {
        return "copyright 2007-1010";
    }
    }

的web.xml

<web-app>
<servlet>
<servlet-name>FirstServlet</servlet-name>
<servlet-class>FirstServlet</servlet-class>
</servlet>

<servlet-mapping>
<servlet-name>FirstServlet</servlet-name>
<url-pattern>/FirstServlet</url-pattern>
</servlet-mapping>

</web-app>

1.解决此错误的解决方案是什么

2.设置所有环境变量(JAVA_HOME,PATH,CLASSPATH)

3.执行程序的需要解决方案是Eclipse IDE。

1 个答案:

答案 0 :(得分:0)

确保您的servlet类对

不可见
<servlet-class>FirstServlet</servlet-class>

你需要改变

<servlet-class>com.servlet.learning.FirstServlet</servlet-class>