java - 从webapp项目外导入jsp和html页面

标签 java jsp spring-mvc tomcat

我正在尝试在 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 页面。

这是目录结构 enter image description here

最佳答案

可以按照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/

相关文章:

java - 错误 GXJMake : "Index was out of range. Must be non-negative and less than the size of the collection"

java - 动态创建行时如何为行提供替代颜色?

java - 如何在不使用任何 String、StringBuilder 的情况下打印最多 1000 个的所有回文?

java - Java 解析字符串

java - 在jsp里面写java有性能差异吗?

javascript - 使用 jSTL 数组填充 javascript 数组

java - Spring - Oauth2 客户端服务器。 NoSuchMethodError : javax. servlet.ServletContext.getVirtualServerName() 在 tomcat 中运行时

Java Spring框架-Bootstrap集成

java - 使用 loadUserByUsername 时出现 NullPointerException

java - SQL 到 JOOQ 翻译 : type error