Results 1 to 7 of 7
- 08-03-2010, 10:57 AM #1
Member
- Join Date
- Aug 2010
- Posts
- 4
- Rep Power
- 0
Problem trying to display a .jpg image file on a web browser
Hi guys, I am currently using an eclipse ganymede IDE to write and compile my code. I want to import and display a .jpg picture on a java server page. The picture displays successfully when I compile my code and run it on my eclipse web browser, but, the same does not happen when I type the same url on Internet explorer address bar. All the data gets displayed except my picture.
I find this very weird because, eclipse uses an Internet Explorer browser.
I even tried creating a .war file of my project and running it seperately on a tomcat server and the same thing happens. The picture file does not get displayed on the web browser.
Can someone tell me what my problem could be? Do I have to enable any settion on Internet Explorer?
Thanks!
- 08-03-2010, 01:58 PM #2
Moderator
- Join Date
- Apr 2009
- Posts
- 10,484
- Rep Power
- 16
When you deploy it to tomcat can you find the picture in the correct place, presumably <app>/images/mymage.jpg?
- 08-03-2010, 07:21 PM #3
Member
- Join Date
- Aug 2010
- Posts
- 4
- Rep Power
- 0
Thanks for your response.
No, my images are stored on the local drive. eg) C:/Program files/ images/image.jpg
Do I have to store it inside teh webapps folder?
- 08-04-2010, 08:54 AM #4
Moderator
- Join Date
- Apr 2009
- Posts
- 10,484
- Rep Power
- 16
Yep.
In HTML the img tag uses a URL (either relative or full) to reference an image. It will not recognise something on your harddrive when run through a web server.
- 08-04-2010, 07:20 PM #5
Member
- Join Date
- Aug 2010
- Posts
- 4
- Rep Power
- 0
ok. That makes sense. This is what I have done.
String output = "C:/Users/Owner/Desktop/" + "images/Level2.jpg";
<img src="<% out.print(output);%>" alt="Level2" />
Could you tell me what I should do to get the url dynamically?
Should I save the .jpg file inside 'webapps' folder? If yes, how do I get the url path of my application?
Kindly advice. would really appreciate it.
Thanks
- 08-04-2010, 08:25 PM #6
Member
- Join Date
- Aug 2010
- Posts
- 4
- Rep Power
- 0
I just created a folder called images inside webapps and got the real path using
getServletContext().getRealPath()
This is thecode:
String appPath = getServletContext().getRealPath("/images/")+"\\";
String output = appPath + "Level1_oType.jpg";
The jpg files are getting stored inside the images folder. When I retrieve them using image src, the image does not get displayed.
<img src="<% out.print(output);%>" alt="Level1_oType.jpg" />
Any suggestions?
- 08-05-2010, 08:41 AM #7
Moderator
- Join Date
- Apr 2009
- Posts
- 10,484
- Rep Power
- 16
Similar Threads
-
Sending image file over serversocket to browser client
By maheshsk in forum Advanced JavaReplies: 1Last Post: 12-10-2009, 02:40 PM -
Sending image file over serversocket to browser client
By maheshsk in forum Web FrameworksReplies: 1Last Post: 12-10-2009, 02:39 PM -
image problem when using any browser
By ocean in forum New To JavaReplies: 3Last Post: 09-17-2009, 10:29 PM -
[SOLVED] Display the text.log file in the browser
By jazz2k8 in forum Advanced JavaReplies: 2Last Post: 06-09-2009, 02:23 PM -
Display MS-Word file in browser
By jazz2k8 in forum Advanced JavaReplies: 6Last Post: 12-08-2008, 12:59 PM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks