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

关于调用SERVLET
<!--这个是SERVLET文件-------------------------------->
package   hall;

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

public   class   serv   extends   HttpServlet   {
public   void   doGet(HttpServletRequest   request,
HttpServletResponse   response)
throws   ServletException,   IOException   {
PrintWriter   out   =   response.getWriter();
out.println( "Hello   World ");
}
}

<!--这个是WEB。XML文件---->
<web-app   xmlns= "http://java.sun.com/xml/ns/j2ee "
        xmlns:xsi= "http://www.w3.org/2001/XMLSchema-instance "
        xsi:schemaLocation= "http://java.sun.com/xml/ns/j2ee   http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd "
        version= "2.4 ">

    <display-name> Welcome   to   Tomcat </display-name>
    <description>
          Welcome   to   Tomcat
    </description>
<!--   JSPC   servlet   mappings   start   -->

        <servlet>      
                    <servlet-name> serv </servlet-name>      
                    <servlet-class> hall.serv </servlet-class>      
            </servlet>      
               
            <servlet-mapping>      
                    <servlet-name> serv </servlet-name>      
                    <url-pattern> /serv </url-pattern>      
            </servlet-mapping>      

<!--   JSPC   servlet   mappings   end   -->

</web-app>

serv.class目录:C:\Program   Files\Apache\Tomcat   5.5\webapps\eweb\WEB-INF\classes\hall\serv.class
web.xml目录:C:\Program   Files\Apache\Tomcat   5.5\webapps\eweb\WEB-INF\web.xml


请问各位高手XML有什么错误吗?如果没有错我怎么才能访问serv.class




------解决方案--------------------
如果没有错

http://localhost:8080/eweb/serv
------解决方案--------------------
你说的确实是没有意义的。因为hall.serv与hall/serv只不过是两种表示法。打包的时候package hall.xx.xx...的作用是按目录顺序,hall/serv也是按目录顺序,要说区别也只是在具体环境有不同规定的表示法。
------解决方案--------------------
你在web.xml配置的servlet路径是什么,那你就怎么访问
http://localhost:8080/eweb/servlet的配置路径
------解决方案--------------------
使用http://localhost:8080/eweb/serv
------解决方案--------------------
那也不一定一定是http;//localhost:8080/eweb/serv
也有可能是http://localhost:8080/servlets/eweb.serv