我上传了一些图片,并将其保存到此路径中的目录中: C:\ Users \ user \ Inoesis Spring Projects.metadata.plugins \ org.eclipse.wst.server.core \ tmp0 \ wtpwebapps \ HDTS / photos。
I have uploaded some images and it got saved into a directory in this path:
C:\Users\user\Inoesis Spring Projects\.metadata\.plugins\org.eclipse.wst.server.core\tmp0\wtpwebapps\HDTS/photos. Handler method in the Controller:
@RequestMapping(value={"/", "home"})
public ModelAndView showIndex(){
return new ModelAndView("index", "artistList", artistService.getArtistsByLikes());
}
view : index.jsp
<c:if test="${not empty artistList }">
<c:forEach items="${artistList }" var="artistInfo">
<div class="col-md-4">
<div class="panel panel-default">
<div class="panel-heading">
<h3 class="panel-title"> <span class="glyphicon glyphicon-user"></span> <c:out value="${ artistInfo.stageName}"/> </h3>
</div>
<div class="panel-body">
<img alt="" src="<%=request.getContextPath()%>/photos/${artistInfo.photoName}">
</div><!-- /.panel-body -->
</div><!-- /.panel panel-primary -->
</div><!-- /.col-md-4 -->
</c:forEach>
</c:if>
Pls note my project is HDTS.
How do i display them on a jsp page.
thanks
请注意我的项目是HDTS。 如何在jsp页面上显示它们。 感谢
答案 0 :(得分:0)
您可以将上传的图片名称发送到请求的页面,并使用HttpServletRequest中定义的 getContextPath()来获取上传图片的完整网址。
<%=request.getContextPath()%>
将提供/ wtpwebapps / HDTS
所以你的<img />
应该是这样的:
<img src="<%=request.getContextPath()%>/photos/${image_name}"/>
希望这有帮助。
快乐的编码!干杯!!