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 40开发者_开发问答4 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?
You can write a filter for that, if you don't want to change the servlet code.
Have a look at URL Rewriter. It's implemented as a Filter.
http://code.google.com/p/urlrewritefilter/
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
.
精彩评论