web.xml:
<?xml version="1.0" encoding="UTF-8"?>
<web-app version="2.5" 
xmlns="http://java.sun.com/xml/ns/javaee" 
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee 
http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd">
  <servlet>
    <description>This is the description of my J2EE component</description>
    <display-name>This is the display name of my J2EE component</display-name>
    <servlet-name>testServlet2</servlet-name>
    <servlet-class>servlet.testServlet2</servlet-class>
  </servlet>  <servlet-mapping>
    <servlet-name>testServlet2</servlet-name>
    <url-pattern>/test</url-pattern>
  </servlet-mapping>
  <welcome-file-list>
    <welcome-file>index.jsp</welcome-file>
  </welcome-file-list>
  
</web-app>
jsp:
<%@ page language="java" import="java.util.*,common.DBConnection" pageEncoding="gbk"%><!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%><html>
  <head>
  </head>
  
  <body>
  <a href="test">do</a>
  </body>
</html>
servlet包下的testServlet2:
package servlet;import java.io.IOException;
import java.io.PrintWriter;import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;public class testServlet2 extends HttpServlet { /**
 * Constructor of the object.
 */
public testServlet2() {
super();
} /**
 * The doGet method of the servlet. <br>
 *
 * This method is called when a form has its tag value method equals to get.
 * 
 * @param request the request send by the client to the server
 * @param response the response send by the server to the client
 * @throws ServletException if an error occurred
 * @throws IOException if an error occurred
 */
public void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException { response.setContentType("text/html");
PrintWriter out = response.getWriter();
out
.println("<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.01 Transitional//EN\">");
out.println("<HTML>");
out.println("  <HEAD><TITLE>A Servlet</TITLE></HEAD>");
out.println("  <BODY>");
out.print("    This is ");
out.print(this.getClass());
out.println(", using the GET method");
out.println("  </BODY>");
out.println("</HTML>");
out.flush();
out.close();
}}
报错:
type Status reportmessage /ownHome_Version_0107_00/testdescription The requested resource (/ownHome_Version_0107_00/test) is not available.

解决方案 »

  1.   

     找到原因了,自己贴答案,来人接分
    在IE中提示“404”错误有以下三种情况1.未部署Web应用
    2.URL输入错误
           排错方法:首先,查看URL的IP地址和端口号是否书写正确。       其次,查看上下文路径是否正确 Project--------Properties------MyElipse-----Web-----Web Context-root检查这个路径名称是否书写正确。最后,检查一下文件名称是否书写正确。3.目录不能被引用
           排错方法:       在 Eclipse的“包资源管理器(Package Explorer)”检查文件存放的位置。由于META-INFWEB-INF文件夹下的内容无法对外发布,所以,如果你引用了带这两个目录的文件,肯定是不允许。例如: http://localhost:8080/guestbook/WEB-INF/index.html就是错误的文件位置存放错误4. Tomcat服务器中web.xml中的问题 
           排错方法:      如果你的web应用程序有多个jsp页面的话,当你点击你web应用程序的虚拟根目录时可能会出现404错 误,只是你只需要修改Tomcat服务器中web.xml        <init-param>
                <param-name>listings</param-name>
                <param-value>false(将其该为true)</param-value>
            </init-param> 
    本文来自CSDN博客,转载请标明出处:http://blog.csdn.net/IBM_linghb1985/archive/2009/02/06/3866817.aspx