..但我想我做的每件事都是正确的......请建议
我需要知道如何创建一个简单的servlet应用程序..在继续之前是否有任何设置在环境变量中的东西..我已经创建了helloworld servlet pgm但是获取404错误请求的资源不可用..
servlet类
package com.ignis;
import java.io.*;
import javax.servlet.*;
import javax.servlet.http.*;
public class Hello extends HttpServlet {
/**
*
*/
private static final long serialVersionUID = 1L;
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" 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>devProj</display-name>
<welcome-file-list>
<welcome-file>Hello</welcome-file>
</welcome-file-list>
<servlet>
<servlet-name>HelloWorld</servlet-name>
<servlet-class>Hello</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>HelloWorld</servlet-name>
<url-pattern>/HelloWorld</url-pattern>
</servlet-mapping>
</web-app>
答案 0 :(得分:4)
servlet类声明应该是
<servlet>
<servlet-name>HelloWorld</servlet-name>
<servlet-class>com.ignis.Hello</servlet-class>
</servlet>
您需要HttpServlet
实施的完全限定类名。我很惊讶它甚至跑了。
答案 1 :(得分:4)
您必须在web.xml
中提供servlet类的完全限定名称。像这样:
<servlet>
<servlet-name>HelloWorld</servlet-name>
<servlet-class>com.ignis.Hello</servlet-class>
</servlet>