0

Is there a way for some specific urls to be excluded from being intercepted by the spring mvc controller?

web.xml

 <servlet>
    <servlet-name>mvc-dispatcher</servlet-name>
    <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
    <load-on-startup>1</load-on-startup>
  </servlet>

  <servlet-mapping>
    <servlet-name>mvc-dispatcher</servlet-name>
    <url-pattern>*.jsp</url-pattern>
  </servlet-mapping>

controller:

@RequestMapping(value="getState.jsp", method = RequestMethod.GET)
    public @ResponseBody Map<String,? extends Object> loadStates() {

....... }

Now if I request index.jsp,it would say 'No mapping found' and the page would not be rendered.
What's the best practice to avoid this situation in annotation-based deployments?

IUnknown
  • 9,301
  • 15
  • 50
  • 76
  • This thread might be helpful: http://stackoverflow.com/questions/1234298/can-springmvc-be-configured-to-process-all-requests-but-exclude-static-content – Ernestas Kardzys Sep 27 '13 at 07:53

1 Answers1

2

The general way of excluding certain URLs from being intercepted by the dispatcher servlet is by adding this:

 <servlet-mapping>
   <servlet-name>default</servlet-name>  
   <url-pattern>URLYouWantToExclude</url-pattern>
 </servlet-mapping>

This should work in Tomcat and Jetty.

shazinltc
  • 3,616
  • 7
  • 34
  • 49