【问题标题】:Can't run the Servlet无法运行 Servlet
【发布时间】:2012-03-15 14:01:47
【问题描述】:

我的电脑上安装了 jdk1.5.0_04 和 tomcat server 1.0.16。 在我的计算机上,servlet 在命令提示符下正确编译,但在浏览器上执行 servlet 期间,使用以下 url:http://localhost:8080/webdir/servlet/helloworld。 它给出的错误如下: HTTP 状态 404 - /servlet/webdir/helloworld

输入状态报告

消息/servlet/webdir/helloworld

description 请求的资源 (/servlet/webdir/helloworld) 不可用。 Apache Tomcat/6.0.16

【问题讨论】:

    标签: java servlets


    【解决方案1】:

    能否请您仔细检查一下您的部署描述符 (web.xml)?它应该看起来像这样:

        <web-app version="2.4"
    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">
    
        <servlet>
            <servlet-name>ServletExample</servlet-name>
            <servlet-class>com.sarath.kumar.sivan.ServletExample</servlet-class>
        </servlet>
        <servlet-mapping>
            <servlet-name>ServletExample</servlet-name>
            <url-pattern>/ServletExample</url-pattern>
        </servlet-mapping>
        <welcome-file-list>
            <welcome-file> /pages/form.html </welcome-file>
        </welcome-file-list>
    </web-app>
    

    你的 .html 页面应该是这样的:

    <form method="POST" action="ServletExample">
    

    【讨论】:

      猜你喜欢
      • 2014-09-25
      • 2014-06-27
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-08-29
      • 1970-01-01
      • 2014-01-30
      • 1970-01-01
      相关资源
      最近更新 更多