display images in a Web Application based on java/jsp
This is my first post here and not sure if this is the right place to ask this question. Let me know if I have to repost my question elsewhere.
So here is my question:
I am currently working on a web app. It has got lots of java code, jsp file, xml etc. On one of the JSP pages I have to display some images. There is a dedicated folder storing all images and icons. I have to get some images from the dedicated image folder and display them on the JSP page. But I am trying to do this dynamically, I don't want to hardcode the images' location in the JSP or Java code. I am calling a java method
This returns me a folder which is not the Web App's root. I would prefer getting web app's root but that is not an issue at this time. The folder that above line of code returns is not where the images and icons are, so what I do in my java code is that, I move up some folders and then mode down a few folder and get to the location where images and icons are stored. Even in this I am making assumptions and this code may fail if for some reason folder hierarchy is disturbed/modified.
But anyway, what I don't understand is that my images and icons get displayed in Internet Explorer but Firefox fails to show those images & icons.
Even though, I am trying not to hardcode any image path, I am unintentionally doing it. Becuase getResource("/") returns me a path something like
And this is what I think Firefox doesnt like, an absolute path.
Can anyone suggest a better way of doing this? Obviously webapps will be on a server, users will be connecting to the webapp via their browsers but I guess I need to have some way of sending the image over to the users' browser. How do I do something like this?