I’ve got a controller set up in my web.xml:
<servlet>
<servlet-name>controller</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>controller</servlet-name>
<url-pattern>/console/index</url-pattern>
</servlet-mapping>
And a matching bean defined in controller-servlet.xml:
<bean name="/console/index" class="com.package.OverviewController"/>
Which works correctly – when I get “/appName/console/index” it behaves as I expect. But when I change web.xml to this:
<servlet>
<servlet-name>controller</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>controller</servlet-name>
<url-pattern>/console/*</url-pattern>
</servlet-mapping>
It no longer functions, giving me the following exception:
WARN (org.springframework.web.servlet.PageNotFound) - No mapping for [/appName/console/index] in DispatcherServlet with name 'controller'
So my question is how do I use wildcards in the servlet mappings, so that different URLs all go through the single DispatcherServlet but may go to one of several controller beans?
FYI: I’m stuck on Spring 2.0, as it’s an established application used in government.
When you use wildcards in
<url-pattern>, controller names by default correspond to wildcard part of the pattern.So, you can either rename your controller to
/index, or set thealwaysUseFullPathproperty of yourHandlerMappingtotrue.