大家好,我是新手加自学 
现在有个servlet中编写jsp文件后无法找到资源的问题,请大家看看 
程序老师说是对的,估计主要是出现在配置上: 
本想编写个显示在servlet中get和post传递参数的不同的例子 
程序如下: 
//----------------ParamForm.jsp------------------------- 
<%@ page language="java" import="java.util.*" contentType="text/html; charset=gb2312" 
    pageEncoding="gb2312"%> 
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> 
<html> 
<head> 
<meta http-equiv="Content-Type" content="text/html; charset=gb2312"> 
<title>Insert title here </title> 
</head> 
<body> 
<font size="2"> 
      <form action="RequestParam" method="post"> 
        姓名: <input type="text" name="name"/> <br> 
        省份: <input type="text" name="province"/> <br> 
        <input type="submit" value="提交"> 
        </form> 
        </font> 
</body> 
</html> 
//----------------------------------------------------- //-----------------------RequestParam.java------------- 
package ch7; import java.util.*; 
import java.io.*; 
import java.io.IOException; 
import javax.servlet.ServletException; 
import javax.servlet.http.HttpServletRequest; 
import javax.servlet.http.HttpServletResponse; /** 
* Servlet implementation class for Servlet: RequestParam 

*/ 
public class RequestParam extends javax.servlet.http.HttpServlet implements javax.servlet.Servlet { 
    
public RequestParam() { 
super(); 
}  
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { 
response.setContentType("text/html"); 
response.setCharacterEncoding("gb2312"); 
Enumeration e=request.getParameterNames(); 
PrintWriter out=response.getWriter(); 
out.println(" <font size='2'>"); 
out.println("下面是用GET方法传递过来的参数: <br>"); while(e.hasMoreElements()) 

String name=(String)e.nextElement(); 
String value=request.getParameter(name); 
out.println(name+"="+value+" <br>"); 

out.println(" </font>"); 
}  
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { 
response.setContentType("text/html"); 
response.setCharacterEncoding("gb2312"); 
Enumeration e=request.getParameterNames(); 
PrintWriter out=response.getWriter(); 
out.println(" <font size='2'>"); 
out.println("下面是用POST方法传递过来的参数: <br>"); while(e.hasMoreElements()) 

String name=(String)e.nextElement(); 
String value=request.getParameter(name); 
out.println(name+"="+value+" <br>"); 

out.println(" </font>"); 
}        

//------------------------------------------------ 运行RequestParam.java可以成功,但是运行ParamForm.jsp显示 
HTTP Status 404 - /RequestParam/ParamForm.jsp -------------------------------------------------------------------------------- type Status report message /RequestParam/ParamForm.jsp description The requested resource (/RequestParam/ParamForm.jsp) is not available. 
-------------------------------------------------------------------------------- Apache Tomcat/5.5.20 
请教一下不知道问题出现在哪里?谢谢,很迷茫

解决方案 »

  1.   

    /RequestParam/ParamForm.jsp 
    没找到这个路径
    你tomcat里这个文件的路径是什么样的?
      

  2.   

    是你web.xml里面的servlet配置有问题,也就是你servlet路径问题, <form action="RequestParam" method="post"> 你这里action用的是直接的servlet名字,所以你配置servlet的时候<url-pattern>/RequestParam</url-pattern>应该是这样的
      

  3.   

    是呀 我的web.xml配置是
             <servlet>
    <description>
    </description>
    <display-name>
    RequestParam</display-name>
    <servlet-name>RequestParam</servlet-name>
    <servlet-class>
    ch7.RequestParam</servlet-class>
    </servlet>
    <servlet-mapping>
    <servlet-name>RequestParam</servlet-name>
    <url-pattern>/RequestParam</url-pattern>
    </servlet-mapping>
     运行后的地址是http://localhost:8080/MyProject/RequestParam/ParamForm.jsp
      理论上应该是http://localhost:8080/MyProject/ParamForm.jsp
    多了个/RequestParam,应该怎么改呀?
      

  4.   

    http://localhost:8080/MyProject/ParamForm.jsp 
    本来就是这个啊,这是你在浏览器中输入的啊
    你为什么要访问http://localhost:8080/MyProject/RequestParam/ParamForm.jsp
    这个地址?
      

  5.   

    是呀 我运行jsp程序他自己就访问http://localhost:8080/MyProject/RequestParam/ParamForm.jsp
    需要我手动改为http://localhost:8080/MyProject/ParamForm.jsp才成功呀 
    这个问题怎么解决呀?
      

  6.   

    你需要在你SERVLET中指定要跳转的路径,如果不指定就是你的根路径。现在你的根路径没有找到,所以就找不到你页面
      

  7.   

    是呀 我运行jsp程序他自己就访问http://localhost:8080/MyProject/RequestParam/ParamForm.jsp
    需要我手动改为http://localhost:8080/MyProject/ParamForm.jsp才成功呀
    这个问题怎么解决呀?
    --------------------------------------------------------------------
    我猜想,你的情况有两个可能,楼上的说法应该不是。
    1.web.xml的配置,欢迎页配成了/MyProject/RequestParam/ParamForm.jsp
    2.index.jsp,自动跳转写成了/MyProject/RequestParam/ParamForm.jsp