tomcat-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Craig R. McClanahan" <Craig.McClana...@eng.sun.com>
Subject Re: Turning off /servlet/* mapping?
Date Fri, 01 Dec 2000 20:38:44 GMT
Thom Park wrote:

> I'm having Yet Another Servlet Mapping Problem.
>
> I'm trying to disable the /servlet/ mapping with my web-application. Here's the
> gist of what's happening.
>
>  My webapp is called "songs" it get's deployed according to J2EE specs. In the
> webapps folder there's a
> songs folder with an html file called songs_index.html.
>
> in songs\WEB-INF, I put my servlet into the classes folder (and some dependent
> jars in the lib folder).
>
> In web.xml I add the following:
>
> <servlet>
> <servlet-name>listSongs</servlet-name>
> <servlet-class>com.music.songs.ListSongServlet</servlet-class>
> </servlet>
>

Add the following mapping in web.xml:

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

and the following URL will work:

    http://localhost:8080/songs/listSongs

You don't really need to "turn off" the default mapping -- what we are doing here is
defining a new one.  You should also know that the path used in a mapping need not
have the same name as your servlet class.  For instance, if you change the mapping
above to this:

    <servlet-mapping>
        <servlet-name>listSongs</servlet-name>
        <url-pattern>/list/*</url-pattern>
    </servlet-name>

then the correct URL would be

    http://localhost:8080/songs/list

instead.

The rules for servlet mappings are found in the servlet API specification, which can
be downloaded from

    http://java.sun.com/products/servlet/download.html

Craig McClanahan



Mime
View raw message