I have an application and so web.xml. In web.xml I configured error page as below
<error-page>
<error-code>404</error-code>
<location>/error/err404.jsp</location>
</error-page>
The above thing works perfectly for a uri that is not exists in web.xml.
For Eg:
1. localhost:8080/appName/testServlet (Exists in web.xml)
2. localhost:8080/appName/testServletXXX (Not exists)
Both urls work perfectly(first url renders actual page, second url renders err404.jsp) when I enter urls directly on browser.
When I forward the request to uri "testServlet ", it works fine as it exists in web.xml. The problem comes when the uri(testServletXXX) is not exist in web.xml. If uri is not exists in web.xml, it is not rendering err404.jsp instead it is rendering error:
HTTP Status 404 - /appName/xxxx
type Status report
message /appName/xxxx
description The requested resource is not available.
Apache Tomcat/7.0.32
which is from tomcat.
Below is the code for forwarding request.
ServletContext scRoot = getServletConfig().getServletContext().getContext("/appName");
rd = scRoot.getRequestDispatcher("testServlet");
rd.forward(request, response);
Why the error-page is not rendering err404 page for the uri that is not exist in web.xml. It is happening especially in forwarding case. Am not able to figure it out. Did I miss any concept/ logic. Appreciate any help. Thanks in advance.
Yeah, I found solution myself. Actually, my application has multiple components and each component treated as a webapp. So, each component has own web.xml. Now, what I am doing is, Am forwarding request from one component to another component. Let us say, forwarding from App1 to App2. I have specified error-page tag info in App2 web.xml only. But not in App1. When I put same error-page tag info in App1 web.xml(From where am forwarding request to App2), then every thing works fine. Thanks Serge Ballesta for trying to help me out. I guess my question is not giving enough info to answer. I am posting answer to help some one who is about to face same situation.