Overclock.net banner

1 - 1 of 1 Posts

·
Linux Lobbyist
Joined
·
3,744 Posts
Discussion Starter #1
OK, I'm trying to diagnose Servlet mapping on a Apache Tomcat installation.

This is the Servlet I created just to diagnose the problem:

Code:

Code:
package com.example.test.server;

import java.util.logging.*;

import javax.servlet.*;
import javax.servlet.http.*;

public class HelloWorldServlet extends HttpServlet {

        private Logger logger = Logger.getLogger("HelloWorld");

        /**
       *  Constructor
        */
        public HelloWorldServlet() {
                super();
        }

        public void init() {
                logger.info("init() called.");
        }

        public void destroy() {
                logger.info("destroy() called.");
        }

        public void doGet(HttpServletRequest request, HttpServletResponse response) {
                logger.info("doGet(): called.");
        }

        public void doPost(HttpServletRequest request, HttpServletResponse response) {
                logger.info("doPost(): called.");
        }
}
and this is the web.xml file:

Code:

Code:
<?xml version="1.0" encoding="UTF-8"?>

<!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>
        <!-- General description of your web application -->
        <display-name>Hello World</display-name>
        <description>Hello, world!</description>

        <servlet>
                <servlet-name>HelloWorldServlet</servlet-name>
                <description>Hello World Servlet</description>
                <servlet-class>com.example.test.server.HelloWorldServlet</servlet-class>
                <load-on-startup>1</load-on-startup>
        </servlet>    
        <servlet-mapping>
                <servlet-name>HelloWorldServlet</servlet-name>
                <url-pattern>/HelloWorldServlet</url-pattern>
        </servlet-mapping>
</web-app>
However, pointing wget at the URI http://192.168.1.191:8080/HelloWorldServlet results in 404. I've successfully deployed Servlets before, so what am I missing?

SOLVED
It looks like Tomcat largely ignores the url-mapping tags. The Servlet is under $TOMCAT_HOME/webapps/HelloWorld. If I pass http://192.168.1.191:8080/HelloWorld/HelloWorldServlet to wget, it works as expected. I find this odd, unless I am misunderstanding how the URL mapping works?
 
1 - 1 of 1 Posts
Top