[英]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-MVC和Spring Expression Language(SpEL)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.