Changing Servlet's default response

I have a Java web application that has several servlets with the following mappings.

ServletOne → / one
ServletTwo → / two
ServletThree → / three

When I make a request for an action that doesn't exist, I get 403 (Forbidden) i.e.: / foo. I would like to change this to give 404 (Not Found). How can i do this?

If 404 is the default behavior, then where can I find this setting that throws things off? I tried searching the site, but I couldn't find the search term that gave something related.

TIA!

+2


source to share


2 answers


Make a servlet map in / (which will capture everything) and then do it to return a 404 in your doGet / processRequest calls. This way, you will not rely on any particular application server behavior that you use to configure it.



+4


source


What servlet container are you using?

Tomcat, by default, maps / * to the DefaultServlet (as per $ TOMCAT_HOME / conf / web.xml) for the server I just confirmed will default to 404 if the mapping doesn't exist.



I would suggest starting by looking at your servlet container web.xml file to see if a similar default mapping exists.

0


source







All Articles