/exp1/servlet/com.ser1.HelloWorld servlet不可用

时间:2014-03-03 12:24:32

标签: java xml servlets

您好了创建简单servlet来打印hello world。我也创建了web.xml。我仍然得到error 404 resource not found。 这是servlet代码

package com.ser1;
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 {
           PrintWriter out = response.getWriter();
           out.println("Hello World");
 }
} 

这里是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" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd" version="3.0">
 <display-name>exp1</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>
<servlet-name>hi</servlet-name>
<servlet-class>HelloWorld</servlet-class>
</servlet>
<servlet-mapping>
   <servlet-name>hi</servlet-name>
   <url-pattern>/hello.html</url-pattern>
</servlet-mapping>

1 个答案:

答案 0 :(得分:0)

更改web.xml中的以下代码集,

<servlet-name>hi</servlet-name><servlet-class>HelloWorld</servlet-class></servlet>

 <servlet-name>hi</servlet-name><servlet-class>com.ser1.HelloWorld</servlet-class></servlet>

您尚未在web.xml中正确提及类名