Java 在web.xml中找不到URI为的HTTP请求的映射

Java 在web.xml中找不到URI为的HTTP请求的映射,java,json,spring,spring-mvc,model-view-controller,Java,Json,Spring,Spring Mvc,Model View Controller,在使用Spring MVC和JSON的项目中,我将web.xml文件配置如下: Web.xml <welcome-file-list> <welcome-file>index.html</welcome-file> <welcome-file>index.htm</welcome-file> <welcome-file>index.jsp</welcome-file> </welcome-file-list

在使用Spring MVC和JSON的项目中,我将web.xml文件配置如下:

Web.xml

<welcome-file-list>
<welcome-file>index.html</welcome-file>
<welcome-file>index.htm</welcome-file>
<welcome-file>index.jsp</welcome-file>
</welcome-file-list>    
<context-param>
    <param-name>contextConfigLocation</param-name>
    <param-value>/WEB-INF/spring/root-context.xml</param-value>
</context-param>

<listener>
     <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>

<!-- Processes application requests -->
<servlet>
    <servlet-name>appServlet</servlet-name>
    <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
    <init-param>
        <param-name>contextConfigLocation</param-name>
        <param-value>/WEB-INF/spring/appServlet/servlet-context.xml</param-value>
    </init-param>
    <load-on-startup>1</load-on-startup>
</servlet>      
<servlet-mapping>
    <servlet-name>appServlet</servlet-name>
    <url-pattern>/</url-pattern>
</servlet-mapping>
结果JSON:

[{"name":"dat3","age":33},{"name":"dat4","age":44}]
但如果我想通过URL在位置获取图像,则不成功:

http://localhost:9999/restfulspringmvc/images/avatar.jpg
eclipse中的记录器发出异常警报:

ARN : org.springframework.web.servlet.PageNotFound - No mapping found for HTTP request with URI [/restfulspringmvc/images/avatar.jpg] in DispatcherServlet with name 'appServlet'

如何配置通过浏览器从URL获取图像?非常感谢你

您已将DispatcherServlet配置为使用url模式/这将覆盖容器的默认servlet映射

默认的servlet映射用于加载web.xml中没有显式映射的任何资源或请求。通常,静态资源是使用此方法加载的。如果您通过在web.xml中将其指定为servlet的模式来覆盖它,那么您必须自己加载资源

SpringMVC通过以下方式提供资源处理: 您必须指定与静态资源url模式匹配的映射以及资源物理驻留的位置

你确实指明了

<resources mapping="/resources/**" location="/resources/" />
您的图像位于webapp下的/static resources/images中,您的映射将

<resources mapping="/images/**" location="/static-resources/images/" />


您还可以在同一应用程序上下文中指定多个资源

没有“图像”的URL匹配模式是的,我知道,图像是图像文件夹中的图像,因此我如何配置“图像”的模式?图像驻留在哪里?你有一个包含静态资源(js、css、图像…)的资源文件夹吗?是的,图像的位置:webapp/images/avatar.jpgAs@JimHawkins说没有图像映射。因此,在servlet-context.xml中,您应该有这样的代码,它将添加/images的映射,然后调用http://localhost:9999/images/avatar.jpg
ARN : org.springframework.web.servlet.PageNotFound - No mapping found for HTTP request with URI [/restfulspringmvc/images/avatar.jpg] in DispatcherServlet with name 'appServlet'
<resources mapping="/resources/**" location="/resources/" />
<resources mapping="/images/**" location="/images/" />
http://localhost:9999/restfulspringmvc/images/avatar.jpg
<resources mapping="/images/**" location="/static-resources/images/" />