日期:2014-05-20  浏览次数:20739 次

关于配置自己的servlet的问题(昏迷中的请教)
经过了2天的冥思苦想,已经到了精神崩溃的边缘.特向知情者请教.
联系方式:QQ99222705 
我刚刚学习JSP,在安装JDK时,很顺利.配置变量,也很顺利.安装tomcat与配置时,顺利+顺利.


在C:\Tomcat   5.0\webapps\myapp\WEB-INF目录下,建立了web.xml(代码如下):
<?xml   version= "1.0 "   encoding= "ISO-8859-1 "?>  

<!DOCTYPE   web-app  
PUBLIC   "-//Sun   Microsystems,   Inc.//DTD   Web   Application   2.3//EN "  
"http://java.sun.com/dtd/web-app_2_3.dtd ">  

<web-app>  
<display-name> My   Web   Application </display-name>  
<description>  
A   application   for   test.  
</description>  
</web-app>  


然后在C:\Tomcat   5.0\webapps\myapp下建立了index.jsp代码如下:
<html> <body> <center>  
Now   time   is:   <%=new   java.util.Date()%>  
</center> </body> </html>  


并且顺利的在http://localhost:8080/myapp/index.jsp下显示index.jsp
=================================
然后又建立了一个servlet程序,文件名为Test.java代码如下:
package   test;  
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   Test   extends   HttpServlet   {  
protected   void   doGet(HttpServletRequest   request,   HttpServletResponse   response)  
throws   ServletException,   IOException   {  
PrintWriter   out=response.getWriter();  
out.println( " <html> <body> <h1> This   is   a   servlet   test. </h1> </body> </html> ");  
out.flush();  
}  
}  
并且顺利的生成Test.class文件,把Test\Test.class复制到WEB-INF\classes下
修改web.xml文件为:
<?xml   version= "1.0 "   encoding= "ISO-8859-1 "?>  

<!DOCTYPE   web-app  
PUBLIC   "-//Sun   Microsystems,   Inc.//DTD   Web   Application   2.3//EN "  
"http://java.sun.com/dtd/web-app_2_3.dtd ">  

<display-name> My   Web   Application </display-name>  
<description>  
A   application   for   test.  
</description>  
<servlet>  
<servlet-name> Test </servlet-name>  
<display-name> Test </display-name>  
<description> A   test   Servlet </description>  
<servlet-class> test.Test </servlet-class>  
</servlet>  
<servlet-mapping>  
<servlet-name> Test </servlet-name>  
<url-pattern> /Test </url-pattern>  
</servlet-mapping>  
</web-app>  


刷新http://localhost:8080/myapp/Test后页面显示为:
HTTP   Status   404   -   /myapp/Test

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

type   Status   report

message   /myapp/Test

description   The   requested   resource   (/myapp/Test)   is   not   available.


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