2014-10-09 22 views
0

我正在嘗試使用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 /圖像的圖像

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

和JSP,席力圖召,但沒有成功:

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

檢查與 2014-10-09 17:57:56

+0

我試過了代碼,它不起作用。我也在JSP中嘗試了/home/images/sample.png,但沒有好運 – 2014-10-09 18:52:41

+0

你可以發佈相對路徑和絕對路徑以及你給的配置嗎? – 2014-10-10 04:18:20

回答

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/"/> 
相關問題