我正在尝试在 spring mvc 中的一个 jsp 页面中导入多个 jsp 和 html 页面。我在 apache tomcat 的 server.xml 中添加了 docbase 作为
<Context docBase="/Users/uname/Desktop path="statfiles" />
<Context docBase="BankFeed" path="/helloweb" reloadable="true" source="org.eclipse.jst.jee.server:BankFeed"/></Host>
但是当我在我的 jsp 页面中导入文件时
<c:import var="testfile" url="/statfiles/test.html" />
<c:out value="${testfile}" />
我收到这个警告
WARN : org.springframework.web.servlet.PageNotFound - No mapping found for HTTP request with URI [/helloweb/statfiles/test.html] in DispatcherServlet with name 'appServlet'
如何解决这个问题以及如何在 webapp 项目文件夹之外获取 jsp 和 html 页面。
这是目录结构
最佳答案
可以按照spring-mvc的方式,为静态资源添加映射,位置前缀为file:
所以
<mvc:resources mapping="/statfiles/**" location="file:/Users/uname/Desktop/" />
在SpringMVC中location里面的前缀指示查找策略,有四种类型
classpath: - resources loaded from the classpath.
file: - resources loaded as a URL, from the filesystem.
http: - resources loaded as a URL.
(none) - resources relative to the ROOT
您可以在此处阅读有关在 Spring MVC 中配置静态资源的更多信息 http://docs.spring.io/spring/docs/current/spring-framework-reference/html/resources.html
关于java - 从webapp项目外导入jsp和html页面,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29137849/