hi,
i'm facing the following issue : i have several dispatcher servlets in the same web application, and i would like to deliver a specific 404 error page for each dispatcher servlet
Let's say i have the following dispatcher servlets defined inside my web.xml configuration file :
Now, suppose i try to access the following url :HTML Code:<servlet> <servlet-name>dispatcher1</servlet-name> <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class> <init-param> <param-name>contextConfigLocation</param-name> <param-value>/WEB-INF/configuration/dispatcher1.xml</param-value> </init-param> <load-on-startup>1</load-on-startup> </servlet> <servlet> <servlet-name>dispatcher2</servlet-name> <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class> <init-param> <param-name>contextConfigLocation</param-name> <param-value>/WEB-INF/configuration/dispatcher2.xml</param-value> </init-param> <load-on-startup>1</load-on-startup> </servlet> <servlet-mapping> <servlet-name>dispatcher1</servlet-name> <url-pattern>/dispatcher1/*</url-pattern> </servlet-mapping> <servlet-mapping> <servlet-name>dispatcher2</servlet-name> <url-pattern>/dispatcher2/*</url-pattern> </servlet-mapping>
dispatcher1 would return his own 404 error page (let's call it 404-dispatcher1.jsp), whereas if i try to access this url:
dispatcher2 would return 404-dispatcher2.jsp
Usually, when it comes to error mapping by code, one would have to do it inside the web.xml, this way:
HTML Code:<error-page> <error-code>404</error-code> <location>/WEB-INF/jsp/errors/404.jsp</location> </error-page>
The problem is that i can only define one 404 error page inside that tag, when i need at least 2 different pages depending on the "context" (dispatcher1 / dispatcher2) requested.
I tried to extend DispatcherServlet and override its "noHandlerFound" method to deliver the appropriate 404 page based on the dispatcher servlet handling the request, which worked to some extent. But i'm not really satisfied with this approach since i would also like to map several other error codes like 302, 303,404, 405, 406, and i don't know how to do that with the class extension approach...
According to me, the solution would be to be able to map the 404 <location> path once inside every dispatcher servlet (through one of its controllers) but i couldn't manage to do that : i only succeeded in mapping it to a single dispatcher servlet, like this:
HTML Code:<error-page> <error-code>404</error-code> <location>/dispatcher1/404</location> </error-page>anyone can help me on this one? thanks a lot!Code:// controller managed by spring dispatcher1's context @Controller public class HTTPErrorController { @RequestMapping(value="/404") public String handle404() { return "404-dispatcher1.jsp"; } }


Reply With Quote
