如何访问应用程序外的文件

时间:2014-10-09 17:12:55

标签: jsp spring-mvc

我正在尝试使用Spring MVC和JSP实现一个小应用程序。在我的应用程序中,我想显示一些驻留在应用程序之外的图像,比如/home/images/sample.png。我知道如何通过配置xml来访问图像:

<!-- External css + js + images -->
<mvc:resources mapping="/resources/**" location="/WEB-INF/**>

和JSP

<img src=<c:url value="/resources/images/sample.png" />/>

我尝试应用相同的逻辑来访问/ home / images中的图像

<mvc:resources mapping="/resources/**" location="/WEB-INF/**>
<mvc:resources mapping="/resources/image/**" location="file:/home/images/**" />

在JSP中,我尝试调用它但没有成功:

<img src=<c:url value="sample.png" />/>

1 个答案:

答案 0 :(得分:0)

我认为JSP应该是

<img src=<c:url value="${pageContext.servletContext.contextPath}/resources/image/sample.png" />/>

mvc:资源映射应该类似

<mvc:resources mapping="/resources/**" location="file:/C:/Users/home/directory_contain_image/"/>