views:

47

answers:

1

Hi,

I configured below exception resolver in my web configuration file but I am not sure why it cannot handle errors such as this 'No Matching error found for servlet request: path '/etc'

<bean class="org.springframework.web.servlet.handler.SimpleMappingExceptionResolver">
    <property name="exceptionMappings">
        <props>
            <prop key="java.lang.Exception">
                exception
            </prop>
        </props>
    </property>
</bean>

My app relies on Ajax and there are cases that I change the target url based on some user interactions.

My question is, is it possible for me to catch the error in my Spring MVC and forward it to my exception.jsp so that my user wont get a nasty 404.

+2  A: 

SimpleMappingExceptionResolver (and the HandlerExceptionResolver framework in general) will only be invoked to handle exceptions generated by the request handler (i.e. your controllers). If no handler is configured to handle the request, then it won't get that far, and your resolver won't be invoked.

The simplest thing for you to do is to configure a 404-handling page in your web.xml, e.g.

<error-page>
    <error-code>404</error-code>
    <location>/error.html</location>
</error-page>
skaffman
@skaffman.. you really are the man. Thank you as always... =)
Mark Estrada