简体   繁体   中英

Not able to retrieve images in jsp

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>

Saving the images in path

(C:\workspace\fileupload\.metadata\.plugins\org.eclipse.wst.server.core\tmp0\wtpwebapps\images\user1\) 

in code using .....

new File(request.getSession().getServletContext().getRealPath("../")+"/images"+"/"+auth.getName());

reaching to the deployed webfolder and then coming one step back(as using here ../) then creating a folder "images" then inside images creating a folder with the name of user (as using here +"/"+auth.getName()), saving the images successfully.But while retrieving these image, i tried the code written in jsp, but it is not working.here in jsp , i checked for ${username} and ${imageName} both are retrieving correct values from controller, means there is not any issue with controller side, but while constructing the url for retrieving image, it is getting wrong somewhere.Could someone plz help to get it right

src="../images/${username}/${imageName}"

将您的Image文件夹保存在存储display.jsp的位置,然后重试。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM