Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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?

like image 667
onlyteo Avatar asked Sep 21 '11 09:09

onlyteo


3 Answers

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

like image 160
Ankur Avatar answered Nov 15 '22 08:11

Ankur


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

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

like image 21
Dan MacBean Avatar answered Nov 15 '22 07:11

Dan MacBean


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.

like image 39
palacsint Avatar answered Nov 15 '22 07:11

palacsint