Forcing a 404 error for a specific url template from web.xml

I have a Java servlet that handles requests for any url template on a Tomcat 6 server.

Now I want to block requests to a specific url template by issuing error 404. There is a part of the web service that should no longer be available.

Instead of changing the servlet code, is there a way to force a 404 error for a specific url template using the web.xml file?

+4
source share
3 answers

You can write a filter for this if you do not want to change the servlet code.

+6
source

See the Rewriter URL. It is implemented as a filter.

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

+4
source

Create a new servlet that sends an error message using

response.sendError(HttpServletResponse.SC_NOT_FOUND); 

and map it to your url template with the corresponding servlet-mapping tag in web.xml . If 403 is valid, then simply set the security-constraint tag with (or without) login-config .

+3
source

All Articles