×

Loading...
Ad by
  • 最优利率和cashback可以申请特批,好信用好收入offer更好。请点链接扫码加微信咨询,Scotiabank -- Nick Zhang 6478812600。
Ad by
  • 最优利率和cashback可以申请特批,好信用好收入offer更好。请点链接扫码加微信咨询,Scotiabank -- Nick Zhang 6478812600。

Add <servlet-mapping> in your web.xml.

A servlet is accessible only when you map it to a particular URL in your WEB.XML file. It's very clear in the spec. Please look at the following example of Tomcat.

<servlet-mapping>
<servlet-name>invoker</servlet-name>
<url-pattern>/servlet/*</url-pattern>
</servlet-mapping>

This will map all URLs after "http://<host>/servlet" to the servlet "invoker". For your case, you have to add this portion to map your "HelloWorldExample" to an URL, such as "http://localhost:8080/servlet/hello".
Report

Replies, comments and Discussions:

  • 工作学习 / IT技术讨论 / help on Tomcat 4.1 setup.
    本文发表在 rolia.net 枫下论坛I installed Tomcat 4.1 standalone server on my windown 2000 machine. It serves the webpages fine but did not serve the servlet. It always says that the request resource is not avaiable.

    1) I set it up use the following configuration:
    1. a ) CATALINA_HOME = C:\Tomcat 4.1
    1.b) CLASSPATH = %CLASSPATH%;C:\Tomcat 4.1\common\lib\servlet.jar
    1. c) JAVA_HOME = C:\jdk1.3.1_01

    2) create an servlet in the following directory such as:
    webapps/chapter01/WEB-INF/classes/HelloWorld.class

    3) for the web.xml under /WEB-INF
    <?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>HelloWorldExample</servlet-name>
    <servlet-class>HelloWorldExample</servlet-class>
    </servlet>
    </web-app>

    I do not know what wents wrong. But If I put this class file in the examples directory . It is comes with the installation. It works fine.
    Can anybody give me some clues. Your help will be great appreciated.更多精彩文章及讨论,请光临枫下论坛 rolia.net
    • Check the <servlet-class> field, it should match with the servlet class name: HelloWorld. Also make sure the package of the HelloWorld is correct, here it should not be contained in any package. Good luck!
    • In webLogic, we need another tag in web.html: <servlet-mapping>. I am not sure if it is needed in Tomcat.
    • Add <servlet-mapping> in your web.xml.
      A servlet is accessible only when you map it to a particular URL in your WEB.XML file. It's very clear in the spec. Please look at the following example of Tomcat.

      <servlet-mapping>
      <servlet-name>invoker</servlet-name>
      <url-pattern>/servlet/*</url-pattern>
      </servlet-mapping>

      This will map all URLs after "http://<host>/servlet" to the servlet "invoker". For your case, you have to add this portion to map your "HelloWorldExample" to an URL, such as "http://localhost:8080/servlet/hello".