I'm using the Struts 2 framework for a webapp. While trying to create a custom 404 error page I discovered Struts 2 is doing more work for me then intended.
I only use a struts.xml
and a web.xml
file. In the web.xml
file I added the following code:
<error-page>
<error-code>404</error-code>
<location>/error/Error404.jsp</location>
</error-page>
Now, when I start my webapp it goes to the homepage as usual. When I try urls of this type (all urls that don't exist):
http://localhost:8080/MyWebApp/fhgfhfhfhgfhgfhfhfh
http://localhost:8080/MyWebApp/fhgfhfhfhgfhgfhfhfh.action
Struts will process the request, run the interceptors, and automatically redirect to the default page. I would have expected my 404 error page to be shown on these pages. I even removed this line in struts.xml
but it still redirects!
<default-action-ref name="index" />
When I use the following URL:
http://localhost:8080/MyWebApp/fhgfhfhfhgfhgfhfhfh.jsp
Struts just shows a blank screen and no request is being processed (no interceptors, no redirecting...). I find this weird too because I don't see what's invalid about that request (other than the JSP file that doesn't exist)
So I guess I need to modify my struts.xml
so I can override some default redirecting behaviour (I don't want the 404 error to be covered up by going to the homepage), and my web.xml
to also handle any arbitrary obscure requests (so any URL that is being typed in by the user will at actually be handled instead of just showing blank screens. What am I missing in my configuration?
PS: I'm not talking about Java exceptions/errors, but only the HTTP errors. The Java exceptions are handled properly like I want them to behave.