我的Servlet程序显示404错误,同时部署我的Servlet编程的,是
package com.srccode.example;
import java.io.IOException;
import java.io.PrintWriter;
import javax.servlet.Servlet;
import javax.servlet.ServletConfig;
import javax.servlet.ServletException;
import javax.servlet.ServletRequest;
import javax.servlet.ServletResponse;
public class Jaan 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 IOException,ServletException{
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";}
}
更新:
<?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_3_0.xsd" id="WebApp_ID" version="3.0">
<display-name>HelloWorldServlets</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>
</web-app>
而Tomcat服务器上部署这一计划也显示404错误,为什么?在我的代码中是否有任何错误。浏览器截图中的404错误是 - >http://i.stack.imgur.com/CuPuy.png。解决此问题
在servlet容器的[Tomcat的]日志首先看,以验证是否这个servlet是在网页上下文和这个servlet上装载的任何问题登记。最好提供web.xml及其文件夹结构。 –
创建适当的web.xml文件并在服务器上部署war文件。有关示例web.xml,请参阅http://pubs.vmware.com/vfabric53/index.jsp?topic=/com.vmware.vfabric.tc-server。 2.9 /工具入门/ tutwebapp-Web的XML-file.html – Ruju
@ chandpriyankara我的问题是用'WEB.XML'see更新,并告诉我什么错 –