views:

559

answers:

1

Im not sure that its possible to do what I want to accomplish. I want to map one single servlet to two different URL.

I want both http://10.0.0.1/a and http://10.0.0.1/b to map to the same servlet.

I know its possibe to do the following in web.xml;

  <servlet-mapping>
    <servlet-name>ServletName</servlet-name>
    <url-pattern>/b</url-pattern>
  </servlet-mapping>

But that enables the following url: http://10.0.0.1/ContextPath/b/

+6  A: 

You can do the following:

  <servlet-mapping>
    <servlet-name>ServletName</servlet-name>
    <url-pattern>/a</url-pattern>
  </servlet-mapping>
  <servlet-mapping>
    <servlet-name>ServletName</servlet-name>
    <url-pattern>/b</url-pattern>
  </servlet-mapping>

And then both http://host/webapp/a and http://host/webapp/b will be mapped to the same servlet.

If you want to drop the /webapp prefix, you need to set your web app as the ROOT by setting the path attribtue of the context to "" in your context xml file (under webapps or in META-INF/context.xml)

David Rabinowitz
you mean the context.xml in <TomcatHome>/conf? (and in <Context> add <path>""</path> ? )
Schildmeijer
Yes, it can be there as well. The path is an attribute <Context path="" ...
David Rabinowitz
I've added the following: <Context path="" /> to server.xml. (Also add the the servlet-mappings mentiond above to the webapp specific web.xml) But i still cant get it to wor properly. Any idea?
Schildmeijer
Can you please paste you entire context file? Also, putting it in the server.xml is less prefereable
David Rabinowitz