Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/spring-mvc/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Spring mvc 如何在SpringMVCServlet映射URL中使用通配符?_Spring Mvc - Fatal编程技术网

Spring mvc 如何在SpringMVCServlet映射URL中使用通配符?

Spring mvc 如何在SpringMVCServlet映射URL中使用通配符?,spring-mvc,Spring Mvc,我在我的web.xml中设置了一个控制器: <servlet> <servlet-name>controller</servlet-name> <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class> </servlet> <servlet-mapping> <servlet-na

我在我的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>
因此,我的问题是如何在servlet映射中使用通配符,以便不同的URL都通过单个DispatcherServlet,但可能会进入多个控制器bean中的一个


仅供参考:我被Spring2.0卡住了,因为它是政府使用的一个已建立的应用程序。

当您在
中使用通配符时,默认情况下控制器名称对应于模式的通配符部分

因此,您可以将控制器重命名为
/index
,或者将
HandlerMapping
AlwaySuseSellPath
属性设置为
true

<bean name="/console/index" class="com.package.OverviewController"/>
<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>
WARN (org.springframework.web.servlet.PageNotFound) - No mapping for [/appName/console/index] in DispatcherServlet with name 'controller'