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 web.xml url模式未解析通配符_Spring_Spring Mvc_Web.xml_Request Mapping - Fatal编程技术网

Spring web.xml url模式未解析通配符

Spring web.xml url模式未解析通配符,spring,spring-mvc,web.xml,request-mapping,Spring,Spring Mvc,Web.xml,Request Mapping,我正在运行简单的SpringMVC应用程序。在web.xml中,我使用了以下映射配置: <servlet-mapping> <servlet-name>spring-web</servlet-name> <url-pattern></url-pattern> <!-- root request --> <url-pattern>/endpoint/*</url-pattern>

我正在运行简单的SpringMVC应用程序。在web.xml中,我使用了以下映射配置:

<servlet-mapping>
    <servlet-name>spring-web</servlet-name>
    <url-pattern></url-pattern> <!-- root request -->
    <url-pattern>/endpoint/*</url-pattern> <!-- /endpoint/${name} -->
</servlet-mapping>
但是,当访问路径
/endpoints/something
时,不会触发渲染函数。当我将url模式更改为特定变量名时,如
/endpoint/something
,页面开始处理此类url。为什么通配符与我在url中使用的“whatever”不匹配?这是RequestMapping值的问题吗?我正在使用Tomcat服务器v9.0

web.xml

<web-app xmlns="http://java.sun.com/xml/ns/javaee" 
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee 
http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
version="2.5">

<display-name>Spring3 MVC Application</display-name>

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

<servlet-mapping>
    <servlet-name>spring-web</servlet-name>
    <url-pattern></url-pattern> <!-- root request -->
    <url-pattern>/endpoint/*</url-pattern> <!-- /endpoint/${name} -->
</servlet-mapping>

Spring3MVC应用程序
弹簧网
org.springframework.web.servlet.DispatcherServlet
1.
弹簧网
/端点/*

spring-web-servlet.xml

<beans xmlns="http://www.springframework.org/schema/beans"
    xmlns:context="http://www.springframework.org/schema/context"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xmlns:mvc="http://www.springframework.org/schema/mvc"
    xsi:schemaLocation="
        http://www.springframework.org/schema/beans     
        http://www.springframework.org/schema/beans/spring-beans-3.2.xsd
        http://www.springframework.org/schema/mvc 
        http://www.springframework.org/schema/mvc/spring-mvc-3.2.xsd
        http://www.springframework.org/schema/context 
        http://www.springframework.org/schema/context/spring-context-3.2.xsd">

    <context:component-scan base-package="com.api.web.*" ></context:component-scan>

    <bean class="org.springframework.web.servlet.view.InternalResourceViewResolver">
        <property name="prefix">
            <value>/</value>
        </property>
        <property name="suffix">
            <value></value>
        </property>
    </bean>

    <mvc:resources mapping="/resources/**" location="/resources/" />

    <mvc:annotation-driven />

</beans>

/

提到了两个
,请删除其中一个,然后尝试仅使用
/
代替
/*


这可能会起作用。

提到了两个
,请删除其中一个,然后尝试将
/*
改为仅使用
/


这可能会起作用。

我不理解空
模式的必要性。但是,第一种模式似乎在达到实际模式之前就已经匹配了。使用此设置:

<servlet-mapping>
    <servlet-name>spring-web</servlet-name>
    <url-pattern>/endpoint/*</url-pattern> <!-- /endpoint/${name} -->
    <url-pattern></url-pattern> <!-- root request -->
</servlet-mapping>

弹簧网
/端点/*

我不明白空
模式的必要性。但是,第一种模式似乎在达到实际模式之前就已经匹配了。使用此设置:

<servlet-mapping>
    <servlet-name>spring-web</servlet-name>
    <url-pattern>/endpoint/*</url-pattern> <!-- /endpoint/${name} -->
    <url-pattern></url-pattern> <!-- root request -->
</servlet-mapping>

弹簧网
/端点/*

所以问题是,
/endpoint/*
被认为是我们的RequestMapping控制器应该留下的基础。当与
@RequestMapping(value=“/endpoint/{name}”,method=RequestMethod.GET)
一起使用时,触发控制器的url是两个-
/endpoint/endpoint/{name}
的串联版本。因此,正确的RequestMapping应该是
@RequestMapping(value=“/{name}”,method=RequestMethod.GET)

,所以问题是
/endpoint/*
被认为是RequestMapping控制器的基础。当与
@RequestMapping(value=“/endpoint/{name}”,method=RequestMethod.GET)
一起使用时,触发控制器的url是两个-
/endpoint/endpoint/{name}
的串联版本。因此,正确的RequestMapping应该是
@RequestMapping(value=“/{name}”,method=RequestMethod.GET)

,据我所知,empty用于处理根(“/”url)上的请求。即使我将它们都交换或删除空的一个,“endpoint/whatever”也没有响应。那么为什么不为根添加
/
?据我所知,empty用于处理根(“/”url)上的请求。即使我同时交换它们或者删除空的一个,“endpoint/whatever”也没有响应。那么为什么不为根添加
/