5
votes

I have a Java servlet that that handles requests to any url pattern on a Tomcat 6 server.

Now i want to block requests to a specific url pattern by issuing a 404 error. There is a part of the web service that should not be available anymore.

Instead of changing the servlet code, is there a way for me to forcefully issue a 404 error for a specific url pattern using the web.xml file?

3

3 Answers

6
votes

You can write a filter for that, if you don't want to change the servlet code.

4
votes

Have a look at URL Rewriter. It's implemented as a Filter.

http://code.google.com/p/urlrewritefilter/

3
votes

Create a new servlet which sends an error with

response.sendError(HttpServletResponse.SC_NOT_FOUND);

and map it to your url pattern with a proper servlet-mapping tag in the web.xml. If 403 forbidden is also acceptable just set a security-constraint tag with (or without) login-config.