9 Replies Latest reply on Dec 28, 2010 6:08 PM by jschellSomeoneStoleMyAlias

    how to make a jsp page display locally saved images via absolute path

    807695
      Hello!
      I don't know if this is the appropriate section for this question. I use Java servlets and JSP technology for my application and I would like to display some images saved in a place locally in my computer. So in the JSP page I have something like this:
      <img src="file://Users/...../images/c9ce96fdb2be01f5138808a54086e825.jpg" />
      But I get the following error in the debugger console:

      Not allowed to load local resource: file:///Users/......../images/c9ce96fdb2be01f5138808a54086e825.jpg

      This seems that it finds the file (If I type this in the browser bar it shows the image!) but for a reason it cannot display it. (Maybe security constraints?? )
      I use the Glassfish V.3 server in NetBeans. Do you have any idea of what I should do ??
      Thanks a lot for your time,
      Dimos.
        • 1. Re: how to make a jsp page display locally saved images via absolute path
          EJP
          JSP and servlets and which server you use are completely irrelevant to this question. That <img> tag tells the browser to load a local file, without reference to the server at all, and the error message tells you that it isn't allowed to load a local resource. So it isn't allowed.
          • 2. Re: how to make a jsp page display locally saved images via absolute path
            807695
            So the only way to display the image is to save it inside the project folder?
            Thanks.
            • 3. Re: how to make a jsp page display locally saved images via absolute path
              Kayaman
              Dimos wrote:
              So the only way to display the image is to save it inside the project folder?
              Thanks.
              No, that's not the only way. You can display any images that are accessible through HTTP. What you can't do is use the file:/// prefix (protocol) for displaying it, since a person who views your jsp page doesn't have access to your localhost.
              1 person found this helpful
              • 4. Re: how to make a jsp page display locally saved images via absolute path
                452196
                Dimos wrote:
                So the only way to display the image is to save it inside the project folder?
                Thanks.
                The point is is can't be on the client machine. There's a general security rule that web pages loaded by http do not have access to any files on the client system.


                Normally it will be on the web server.
                1 person found this helpful
                • 5. Re: how to make a jsp page display locally saved images via absolute path
                  807695
                  Actually I will only access from localhost and the server runs on localhost... Its for a university project! So, the solution to store the images inside the project's folder sounds better than uploading them somewhere accessible via http. If you have a better idea just inform me!
                  Thanks a lot for your time!
                  • 6. Re: how to make a jsp page display locally saved images via absolute path
                    452196
                    Dimos wrote:
                    Actually I will only access from localhost and the server runs on localhost... Its for a university project! So, the solution to store the images inside the project's folder sounds better than uploading them somewhere accessible via http. If you have a better idea just inform me!
                    Thanks a lot for your time!
                    If the page is generated by JSP you are presumably accessing it via http anyway. So "putting it in the project's folder" will only work if what you actually mean is "putting it into the web application directory" and, hence, accessing it with http:

                    The client will have no idea where on the file system the projects directory is located.
                    1 person found this helpful
                    • 7. Re: how to make a jsp page display locally saved images via absolute path
                      dadams07
                      This smells like bad design. If you want it to display images from your local computer, why are you using a Web app in the first place? Why not go with Swing or some other non-server framework?
                      • 8. Re: how to make a jsp page display locally saved images via absolute path
                        807695
                        aksarben wrote:
                        This smells like bad design. If you want it to display images from your local computer, why are you using a Web app in the first place? Why not go with Swing or some other non-server framework?
                        This is not a bad design! This application is just for a university project and is about searching files & images from a local location of your computer! It will never get uploaded to a remote accessed web server. If so, we can just place the files in a http accessible location. So its completely healthy to use a Web application in order to invoke the search engine with your query, and display the results to the browser. Much better than having a simple swing. Anyway thanks to all for ur help! We moved the available resources to the project folder and this works fine now.
                        Greetings and happy new year!
                        Dimos.
                        • 9. Re: how to make a jsp page display locally saved images via absolute path
                          jschellSomeoneStoleMyAlias
                          Dimos wrote:
                          This is not a bad design!
                          Either the design and/or the requirements are bad.
                          This application is just for a university project and is about searching files & images from a local location of your computer! It will never get uploaded to a remote accessed web server.
                          The point of using a http server is that you want to access it from a different location.

                          You can defend your implementation by stating that the professor required a single box solution using http. That would be a case of bad requirements on the professors part (but supportable only and solely in the context of learning.) However if you created the requirements then it is your fault. And if you created the design without understanding the point of http (both why you use it and why you don't) then the design/architecture is flawed.