View Full Version : How to route un-mapped URLs to a default controller
echeyde
Apr 27th, 2006, 01:49 AM
hi, I have an app where some URLs are not mapped, like for instance bbb.com/aa/hh.jsp, where hh.jsp does not exist .
I would like such URLs to be routed to a default controller to avoid having the application return a Tomcat JSP not found error.
Can this be solved through the spring app context file and how?
Thanks
-Echeyde
callamits
Apr 27th, 2006, 04:57 AM
Hi,
In the same lines I have this problem, I want to have this scenario:
Many JSP ---> (Using a single Controller) MyFormController
First of all is this possible, if yes what will be the *-servlet.xml changes.
Thanks in Advance,
Regards,
Amit
Colin Yates
Apr 27th, 2006, 05:33 AM
hi, I have an app where some URLs are not mapped, like for instance bbb.com/aa/hh.jsp, where hh.jsp does not exist .
I would like such URLs to be routed to a default controller to avoid having the application return a Tomcat JSP not found error.
Can this be solved through the spring app context file and how?
Thanks
-Echeyde
It all depends on your urlMapping infrastructure. If you are using a mapping (see http://www.springframework.org/docs/reference/mvc.html#mvc-handlermapping) which supports ant style paths then you can simply have a controller which accepts "*". This will be used if all others fail.
jonmor
Apr 27th, 2006, 05:42 AM
It all depends on your urlMapping infrastructure. If you are using a mapping (see http://www.springframework.org/docs/reference/mvc.html#mvc-handlermapping) which supports ant style paths then you can simply have a controller which accepts "*". This will be used if all others fail.
This presupposes that your DispatcherServlet will be set up (in web.xml) to handle any ad-hoc URL, does it not? In most cases, you will have specified the suffix(es) which will tell the DispatcherServlet to handle the URL, with any other URLs 'falling through' to Tomcat's DefaultServlet (assuming you're using Tomcat). Am I not right in thinking that ant style paths are NOT supported in the web.xml, which is where the problem my be?
echeyde
Apr 27th, 2006, 01:20 PM
Thanks for the input. There is another options which is based on the appfuse.org sample and only relies on a web.xml change, without involving Spring.
<error-page>
<error-page>
<error-code>404</error-code>
<location>/error404.jsp</location>
</error-page>
I would prefer a Spring solve though if some XML code can be shown.
vBulletin® v3.7.3, Copyright ©2000-2008, Jelsoft Enterprises Ltd.