File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes JSP and the fly likes Firefox doesnt support images Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » JSP
Bookmark "Firefox doesnt support images" Watch "Firefox doesnt support images" New topic
Author

Firefox doesnt support images

Dilshan Edirisuriya
Ranch Hand

Joined: Apr 22, 2006
Posts: 299
In my jsp I have a coding like this.

<%= application.getRealPath("images")+"/"+"image1.jpg" %>.

The image appears correctly in IE but it doesnt appear in Firefox. What are the possible reasons for this. Do i need to change the code?


Dilshan Edirisuriya SCJP1.4, SCWCD1.4, SCBCD 5
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 41852
    
  63
What is the HTML that gets generated from this, and to which absolute URL does that translate? Is there an image at that URL?


Ping & DNS - my free Android networking tools app
Dilshan Edirisuriya
Ranch Hand

Joined: Apr 22, 2006
Posts: 299
I dont have the full coding right now. The path contains a actual image and it displays fine in the IE but in firefox only the image border is displayed.
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 41852
    
  63
What does "application.getRealPath" do? Is "application" the servlet context? If so, then it can't possibly work, because ServletContext.getRealPath returns a file system path that's valid only on the server, not the browser.
Dilshan Edirisuriya
Ranch Hand

Joined: Apr 22, 2006
Posts: 299
Thanks. The image resides in the web application. How should i handle dynamically changing image paths?
[ August 06, 2007: Message edited by: Dilshan Edirisuriya ]
Ben Souther
Sheriff

Joined: Dec 11, 2004
Posts: 13410

Originally posted by Ulf Dittmer:
What does "application.getRealPath" do? Is "application" the servlet context? If so, then it can't possibly work, because ServletContext.getRealPath returns a file system path that's valid only on the server, not the browser.


It can work but only if you're running a brower on the same machine that is hosting the webserver.


Java API J2EE API Servlet Spec JSP Spec How to ask a question... Simple Servlet Examples jsonf
Michael Ku
Ranch Hand

Joined: Apr 20, 2002
Posts: 510
If the images are part of your web application, then you should be able to make them relative to your web app (start path with "/")
Dilshan Edirisuriya
Ranch Hand

Joined: Apr 22, 2006
Posts: 299
The problem is im using netbeans IDE. In netbeans environment there is a build path also same as the development environment. I have uploaded the images to the build path by getting the real path as above.Thats why i'm using the same syntax to acceess the image. Tell me the correct way of doing this.
Ben Souther
Sheriff

Joined: Dec 11, 2004
Posts: 13410

Regardless of the IDE you're using, JEE applications have a spec driven directory structure. If you want your browser to be able to view images directly (if you want to serve them up as static resources) they will need to be located in the correct place within your web application.

There is a link to the Servlet Spec in my signature.
It is worth taking the time to read it.
Chances are, your IDE will not be present in the production environment so it is important that all the developers on your project know how to deploy and debug your app without it.
Dilshan Edirisuriya
Ranch Hand

Joined: Apr 22, 2006
Posts: 299
Then why does it work in Internet Explorer? Then it should not work in both browsers
Ben Souther
Sheriff

Joined: Dec 11, 2004
Posts: 13410

Originally posted by Dilshan Edirisuriya:
Then why does it work in Internet Explorer? Then it should not work in both browsers


Does it matter?
You're using code that serves up images as local resources; using a path that your users are almost guaranteed not to have on their local machines.
Whether it works in FF on your machine or not, I can assure you it won't work with any browser once you publish it.
Ben Souther
Sheriff

Joined: Dec 11, 2004
Posts: 13410

Originally posted by Dilshan Edirisuriya:
Then it should not work in both browsers

Also, when dealing with client side issues (which, service up local images is..) you can never assume that something will work the same way any two browsers.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Firefox doesnt support images