Spring图像文件访问原因404未找到

时间:2012-10-19 02:03:53

标签: spring

当我将下面的url放在Server上时,我收到404错误

localhost/PDFDemo/resources/jquery/css/ui-lightness/images/ui-bg_highlight-soft_100_eeeeee_1x100.png



Error 404--Not Found

From RFC 2068 Hypertext Transfer Protocol -- HTTP/1.1:

10.4.5 404 Not Found

The server has not found anything matching the Request-URI. No indication is given of whether the condition is temporary or permanent.

If the server does not wish to make this information available to the client, the status code `403 (Forbidden)` can be used instead. The `410 (Gone)` status code SHOULD be used if the server knows, through some internally configurable mechanism, that an old resource is permanently unavailable and has no forwarding address.

我对javascript文件有同样的问题,并通过在web.xml中添加以下内容来解决问题

<mime-mapping>
        <extension>js</extension>
        <mime-type>text/javascript</mime-type>
    </mime-mapping>

我是否可以在contextConfigLocation中放入jsp和图像的等效代码(例如:servlet.xml)。

1 个答案:

答案 0 :(得分:0)

问题是您正在将Spring Dispatcher Servlet映射到根上下文,因此Spring希望处理每个请求(如果您正确配置它本身就不是问题)。添加这样的东西:

<mvc:resources mapping="/resources/**" location="/public-resources/" cache-period="31556926"/>

为您的环境修改应该工作。请参阅文档以了解允许静态资源绕过Spring并转到默认servlet here

您还应该将此添加到您的配置中,以便Spring知道使用默认Servlet。

<mvc:default-servlet-handler/>

此外,this question的答案可能对您有帮助。

相关问题