0
votes

I want to map all requests to a specific servlet but Tomcat won't let me map the /WEB-INF/ directory.

My web.xml file.

<servlet>
    <servlet-name>TestServlet</servlet-name>
    <servlet-class>mypackage.TestServlet</servlet-name>
</servlet>
<servlet-mapping>
    <servlet-name>TestServlet</servlet-name>
    <url-pattern>/*</url-pattern>
</servlet-mapping>

This works fine until you request a page in the /WEB-INF/ directory (gives a 404). Is there any way to map everything, including the /WEB-INF/ directory to a servlet?

I also tried mapping the servlet with /WEB-INF/* and it had no effect.

2

2 Answers

1
votes

No. You cannot access files in WEB-INF from outside directly.

You will have to have a html or a jsp file outside which would redirect the request to files inside WEB-INF folder.

1
votes

As per the tomcat standard, you need to put all your *.html, *.jsp, etc in the application root directory. /WEB-INF directory is mainly used to contain your web.xml, classes and libs but not jsp/htmls. You can't directly navigate to any files/artifacts placed under WEB-INF directory (also valid for META-INF).

This is a security feature of the servlet engine: content under WEB-INF is protected and not accessible from "outside" via URLs. Else, anybody could read sensitive details like application/database configuration, etc. by just assembling appropriate URLs.

You need to follow the guidelines about packaging your web application, read more here:

http://tomcat.apache.org/tomcat-6.0-doc/appdev/deployment.html