Spring:我想在jsp或controller中获取资源的相对路径或完整路径
我有一些用户上传的图片存储在“resource/pics”中,我想在jsp中显示,但路径总是错误的。 我试过了 但它返回:Spring:我想在jsp或controller中获取资源的相对路径或完整路径,spring,resources,path,relative-path,Spring,Resources,Path,Relative Path,我有一些用户上传的图片存储在“resource/pics”中,我想在jsp中显示,但路径总是错误的。 我试过了 但它返回: jndi:/default-host/mvc/resources/pics/bec7838a-55dc-4f8e-86c1-fb9e9067909d.jpg 我的资源在servlet-context.xml中配置 <mvc:resources mapping="/resources/**" location="/resources/" /> 我的资源目录
jndi:/default-host/mvc/resources/pics/bec7838a-55dc-4f8e-86c1-fb9e9067909d.jpg
我的资源在servlet-context.xml中配置
<mvc:resources mapping="/resources/**" location="/resources/" />
我的资源目录输入:/webapp/resources
因此,我的/resources/pics/bec7838a-55dc-4f8e-86c1-fb9e9067909d.jpg位于…/webapp/resources/pics/bec7838a-55dc-4f8e-86c1-fb9e9067909d.jpg
我不需要“jndi:/defaulf主机”。我知道我可以使用子字符串来创建它,但我认为spring框架应该提供一些函数来将资源获取到路径或URL
我想将此资源路径获取给jsp中的用户或jsp页面中使用的控制器
<img src="${pageContext.servletContext.contextPath}/resources/pics/${pictureName}"/>
spring项目中文件夹“resource/pics”的位置是什么?在servlet上下文I config中
<img src="${pageContext.servletContext.contextPath}/resources/pics/${pictureName}"/>
model.addAttribute("pictureName", "picture.jpg")