【发布时间】:2014-12-15 09:45:34
【问题描述】:
display.jsp
<body>
<h1>Displaying Image</h1>
<%
Authentication auth = SecurityContextHolder.getContext().getAuthentication();
session.setAttribute("username", auth.getName());
%>
<c:forEach var="imageName" items="${files}">
${username}${imageName}
<img src="../images/${username}/${imageName}"/>
</c:forEach>
</body>
将图片保存在路径中
(C:\workspace\fileupload\.metadata\.plugins\org.eclipse.wst.server.core\tmp0\wtpwebapps\images\user1\)
在代码中使用.....
new File(request.getSession().getServletContext().getRealPath("../")+"/images"+"/"+auth.getName());
到达已部署的 web 文件夹,然后后退一步(如使用此处 ../)然后创建一个文件夹“images”,然后在图像中创建一个具有用户名的文件夹(如使用此处 +"/"+auth .getName()),成功保存图像。但是在检索这些图像时,我尝试了用 jsp 编写的代码,但它不起作用。在 jsp 中,我检查了 ${username} 和 ${imageName} 都在检索来自控制器的正确值,意味着控制器端没有任何问题,但是在构造用于检索图像的 url 时,它在某处出错了。有人可以帮忙解决一下吗
src="../images/${username}/${imageName}"
【问题讨论】:
-
尝试全名
-
坏主意!!我如何在服务器上下文中使用完全限定名称
标签: java image jsp file-upload