0

I am trying to create a simple application in which a user can add an image. The name of the image and the path of the folder where I am storing the image but when trying to retrieve it. It shows "Not allowed to load local resource: file:///H:/Projectpictures/BrowserForDataTables.PNG" Error on browser console. please have a look and let me know what is it I am doing wrong here. Here is my code.

This is the DAOImplementation code for retrive:

    @Override
@Transactional
public List<pictureModal> allImages() {

    Session currentSession = sessionFactory.getCurrentSession();
    Query<pictureModal> query = currentSession.createQuery("from pictureModal");
    List<pictureModal> pictues= query.getResultList();
    
    return pictures;
}

This is Controller code for getimages:

    @RequestMapping("/seeAllImages")
public String getAllImage(Model theModal) {
    List<pictureModal> myPictures=  pictureServ.allImages();
    theModal.addAttribute("myPicture",myPictures);
    return "ImagePage";
}

And here is the code for JSP file:

    <%@ page language="java" contentType="text/html; charset=ISO-8859-1"
    pageEncoding="ISO-8859-1"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>

<html>
<head>
<title>Pictures will display here</title>
</head>
<body>
<h2>Display Pictures </h2>

    <table border="1">
        <thead>
            <tr>
                <th>Picture Name</th>
                <th>Picture</th>
            </tr>
        </thead>
        <c:forEach var="tempPic" items="${myPicture}">
            <tbody>
                <tr>
                <td>${tempPic.name}</td>
                <td><img src="${tempPic.path}"></td>
                </tr>
            </tbody>
        </c:forEach>
    </table>
</body>
</html>
shivam sharma
  • 41
  • 1
  • 9
  • looks like the path is wrong - file:///H:/Projectpictures/BrowserForDataTables.PNG doesnt look to me like a correct path. Why not put the picture in resources and try to create a relative path from jsp file to the picture? – J Asgarov Aug 01 '20 at 14:47
  • Hi, I have tried this and give the path of the resources folder inside the WebContent it's working now I am able to fetch the images but there is another problem which is every time I upload a new picture and tried to see that uploaded picture it doesn't visible on the page to view and I have to refresh my project from eclipse every time... can you help me with this what should i do to resolve this ? – shivam sharma Aug 04 '20 at 14:43
  • We shouldn’t keep exploring new issues under the same thread - please post a new question describing the new problem and feel free to send me the link to the new post to take a look at. – J Asgarov Aug 04 '20 at 15:32
  • yeah sure!! thanks – shivam sharma Aug 05 '20 at 16:56

1 Answers1

0

Maybe your program tries to access a location where does not have the correct rights. Maybe that is an administrator folder, and your program isn't started as an Administrator.