簡體   English   中英

Spring MVC-從應用程序上下文外部訪問靜態資源

[英]Spring MVC - Access static resources from outside the application context

我有一個Web應用程序,每個JSP都應鏈接到幫助pdf文件。 這些文件位於Web容器/應用程序上下文之外,但位於同一服務器內。

我正在嘗試使用spring mvc資源標簽訪問它們,但仍然無法訪問pdf文件。

任何幫助表示贊賞。

這是Windows env中的配置,文件位於C:\\ workspace \\ shared \\ data \\ help [所有pdf都在這里]

我創建了一個jvm參數來訪問文件-

JVM參數

-Dhelp.dir=/workspace/shared/data/help

Spring MVC資源標簽-

<mvc:resources  mapping="/help/*" location="file:/#{systemProperties.help.dir}/"/>

嘗試訪問pdf時出現404錯誤

Glassfish / JDK 1.6

當我單擊鏈接時,生成的URL是-

http://localhost:8080/workspace/shared/data/help/abc.pdf

我實際的Web應用程序上下文是這樣的-

http://localhost:8080/MyApp

您只需要使用SpEL語法進行小幅修復,

<mvc:resources  mapping="/help/*" location="file:#{systemProperties['help.dir']}"/>

對於JVM參數:

-Dhelp.dir=/workspace/shared/data/help/

用前導和尾部的斜杠將其全部工作

參見: http : //wordgraphs.com/post/1751/Serving-a-resource-from-outside-the-context-root-in-Spring-MVCSpring Expression Language(SpEL)

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM