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

我弄了三个小时未解决,望高手帮我下
前提:我机子里同时装了TOMCAT,和RESIN   ,设置TOMCAT的端口为8081,RESIN的端口为8080,可以正常使用TOMCAT和RESIN中正常的做JSP和JAVABEAN的访问。

现在写的是servlet,   其中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>
<!--   …   -->
<servlet>
<servlet-name> Test </servlet-name>
<servlet-class> moreservlets.TestServlet </servlet-class>
</servlet>

<servlet-mapping>
<servlet-name> Test </servlet-name>
<url-pattern> /UrlTest </url-pattern>
</servlet-mapping>
<!--   …   -->
</web-app>

各个文件的位置如下:TestServlet.class位于/deployDemo/WEB-INF/classes/moreservlets文件夹下,web.xml位于deployDemo/WEB-INF文件夹下,

TestServlet.java的代码如下:
package   moreservlets;

import   java.io.*;
import   javax.servlet.*;
import   javax.servlet.http.*;

/**   Simple   servlet   used   to   illustrate   servlet   naming
*   and   custom   URLs.
*   <P>
*   Taken   from   More   Servlets   and   JavaServer   Pages
*   from   Prentice   Hall   and   Sun   Microsystems   Press,
*   http://www.moreservlets.com/.
*   ?   2002   Marty   Hall;   may   be   freely   used   or   adapted.
*/

public   class   TestServlet   extends   HttpServlet   {
public   void   doGet(HttpServletRequest   request,
HttpServletResponse   response)
throws   ServletException,   IOException   {
response.setContentType( "text/html ");
PrintWriter   out   =   response.getWriter();
String   uri   =   request.getRequestURI();
out.println( " <HTML> "   +
" <BODY   BGCOLOR=\ "#FDF5E6\ "> \n "   +
" <H2> URI:   "   +   uri   +   " </H2> \n "   +
" </BODY> </HTML> ");
}
}


问题如下:
在tomcat下:
我可以使用http://localhost:8081/deployDemo/UrlTest   访问且结果正确
但是不可以使用:http://localhost:8081/deployDemo/servlet/Test   或
                                http://localhost:8081/deployDemo/moreservlets.TestServlet
则不可访问,请问是为啥?

如果把servlet-mapping去掉,用http://localhost:8081/deployDemo/servlet/Test   或http://localhost:8081/deployDemo/moreservlets.TestServlet仍然不可访问,又是为什么啊?

更重要的是在resin下访问:
web.xml文件同上,但是使用http://localhost:8081/deployDemo/UrlTest或http://localhost:8081/deployDemo/servlet/Test   或http://localhost:8081/deployDemo/moreservlets.TestServlet均不可访问,又是为什么啊?

------解决方案--------------------
在tomcat下访问用:http://localhost:8081/deployDemo/UrlTest
在resin下访问用:http://localhost:8080/deployDemo/UrlTest
------解决方案--------------------
绝对路径的写法是:http://localhost:8081/deployDemo/servlet/moreservlets.TestS