日期:2014-05-18  浏览次数:20750 次

难道没有人能解决这个问题,为什么我的servlet老是跑不起来?
我的tomcat的环境变量配置如下:
JAVA_HOME:C:\Program   Files\Java\jdk1.6.0

CATALINA_BASE:E:\Tomcat   5.0

CATALINA_HOME:E:\Tomcat   5.0
 
TOMCAT_HOM:E:\Tomcat   5.0

path:C:\Program   Files\Java\jdk1.6.0\bin

classpath:.;%JAVA_HOME%\lib\dt.jar;%JAVA_HOME%\lib\tools.jar;.;%JAVA_HOME%\lib\dt.jar;   %JAVA_HOME%\lib\tools.jar;%CATALINA_HOME%\common\lib\servlet-api.jar
我测试jsp文件时,没有问题,但是测试servlet时总是报错,以下有一个例子:
fromHtml.html   此文件放在root目录下,如下:
<html>
<head>
<title>
a   form   html   example
</title>
  </head>
  <body   bgcolor= "pink ">
  <form   action= "/doget "   method= "get ">
  input   you   name:   <input   type= "text "   name= "myname "> <br>
  your   loves:   <select   name= "love ">
  <option   value= "sleep "> Sleep </option>
  <option   value= "dance "> Dance </option>
  <option   value= "travel "> Travel </option>
  </select> <br>
  <input   type= "submit "   value= "hand "   name= "submit ">
  <input   type= "reset "   value= "reset "   name= "submit ">
  </form>
</body>
</html>

下面的是servlet文件 
import   java.io.*;
import   javax.servlet.*;
import   javax.servlet.http.*;
public   class   doForm   extends   HttpServlet
{
public   void   doPost(HttpServletRequest   req,HttpServletResponse   res)throws   ServletException,
IOException
{
res.setContentType( "text/html ");
PrintWriter   out=res.getWriter();
out.println( " <html> <head> </head> <body> ");
out.println( "name:   "+req.getParameter( "myname "));
out.println( " <br> ");
out.println( "love:   "+req.getParameter( "love "));
out.println( " </body> </html> ");
out.close();

}
public   void   doGet(HttpServletRequest   req,   HttpServletResponse   res)throws   ServletException,
IOException
{
            doPost(req,res);
}
}
这个文件己经编译过了,而且没有问题,我把它的类文件放在了E:\Tomcat   5.0\webapps\ROOT\WEB-INF\classes目录下.
并且我修改了在
E:\Tomcat   5.0\webapps\ROOT\WEB-INF下的web.xml文件:在 <wed-app> 标签之间添加了以下代码:
<servlet>
<servlet-name> a </servlet-name>
<servlet-class> doForm </servlet-class>
</servlet>
<servlet-mapping>
<servlet-name> a </servlet-name>
<url-pattern> /doget </url-pattern>
</servlet-mapping>
但是通过浏览器访问http://localhost:8080/fromHtml.html  
后,在表单中填写信息以后,提交后:
tomcat   出现如下的报错信息:

HTTP   Status   404   -   /doget

----------------------