我知道网上有很多这样的问题(特别是在这里),但没有什么能真正帮助我 . 我正在使用spring mvc(spring version 3.1.0.RELEASE),我想通过URL访问我的静态数据 .
我的包裹:
-src
- 主要
---资源 -
- 上市
在public里面我有一个test.xml文件 .
这是我的web.xml
- 上市
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>/WEB-INF/spring/ApplicationContext.xml</param-value>
</context-param>
<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/ServletContext.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>
这是我的ServletContext.xml
<!-- Enables the Spring MVC @Controller programming model -->
<annotation-driven />
<!-- Handles HTTP GET requests for /resources/** by efficiently serving up static resources in the ${webappRoot}/resources directory -->
<resources mapping="/resources/public/**" location="/resources/public/" />
现在当我输入这个网址"localhost:8080/bmark-central/resources/public/test.xml"我得到一个404.我尝试了它没有上下文根"localhost:8080/resources/public/test.xml"并且也没有得到我的test.xml(也得到了404) . 我映射错了什么?我在这里错过了什么吗?提前致谢 :)
1 回答
问题可能是静态资源应该与您的webcontent相关 - 因此它们应该在此文件夹中可访问 -
src/main/webapp/resources/public
而不是src/main/resources
.