• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Why won't my images display right in JSP under tomcat?

 
Ranch Hand
Posts: 79
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi chaps,
I am having a pretty serious problem with my web application - the stupid thing won't show images or attach stylesheets. Its like they are linked wrong.
I'm wondering if when you use tomcat and other servlet engines, is there something special you have to do with the image folder or something?
See, I'm pretty sure there isn't anything like that. I've put my images in a folder called images like:
webapps/mywebapp/images
and the actual jsp pages in:
webapps/mywebapps
The jsp pages show up and everything put anything linked is poo pooed.
The thing that's really bugging me though is the fact that when I use the preview page feature in Dreamweaver, the images are shown fine. I've compared the source code via IE and Opera and the code is identical - in fact everything is identical apart from th actual name of the jsp page, because Dreamweaver uses a random name to preview pages
Please, if anyone can help with this I would be very greatful. I'm not sure if its a tomcat/container or maybe even a dreamweaver problem, but its happend every time I've tried to make a webapp so I'm about to go nuts

Thanks to anyone who can offer some suggestions
Kind Regards
Simon
 
Ranch Hand
Posts: 1056
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
What do the <img src="..."> urls look like on your JSP page sources?
What do they look like when Tomcat serves your pages?
 
Ranch Hand
Posts: 152
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I count the same problem some times ago.Dreamweaver using a temp file(like 001454654sdsname.jsp) to brows.To disable this function you will do this:
in Dreamweave toolbar:Edit->parameter selection---->brows in browser->option--->using temp file brows.You will not check out the:"using temp file to brows" option.
 
Simon Harvey
Ranch Hand
Posts: 79
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Guys,
Well, you were spot on there Ron. There was a difference between the two.
The actual code for the page is:
/images/darkblue_gradient.gif
However, if I look at the properties of the image once it's been served I get:
http://localhost:8080/images/darkblue_gradient.gif
BUT what I need it to be is:
http://localhost:8080/qds/images/darkblue_gradient.gif
Notice the qds web application directory.
Do either of you know how i can use relative addressing using Dreamweaver.
I have told Dreamweaver that my default images folder is C:/webapps/qds/images so I'm not sure whats going on here. Of course that default folder is for my local copy
Can you let me know how to set up the addressing for images. That would be so greatly appreciated, I may not even through my monitor out of the window at that stupid dog outside thats constantly all hours day and night. Yes, I think I'll use a the old hand grenade instead. That way i might take out the dogs idiot inbred owners.
Ahem. Sorry. I got a bit sidetracked there!
Many thanks for your help chaps
Simon
 
Ron Newman
Ranch Hand
Posts: 1056
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Try changing it from
img src="/images/darkblue_gradient.gif"
to
img src="images/darkblue_gradient.gif"
that is, take off the "/" at the beginning of the relative URL.
If you're using JSTL, the <c:url> tag might be a better approach.
 
Simon Harvey
Ranch Hand
Posts: 79
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Ron you are a life saver.
Just one last question then:
Whats the difference between putting a / at the very front of a relative address. Me not get it!
Thanks mate, youve been a huge help
Simon
 
Simon Harvey
Ranch Hand
Posts: 79
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Actually guys, I spoke to soon.
The problem is essentially fixed, but there is one irritating problem. When I add an image using dreamweaver, it automatically puts a / in front of the address. This of course is exactly whats screwing things up here.
Does anyone know how I can get round this. I'm certain there must be a way. It seems like a pretty silly problem
Thanks again chaps
Simon
 
Simon Harvey
Ranch Hand
Posts: 79
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi
Sorry, im back. But with good news this time:
I summoned all of my worldly wisdom and managed to fic the problem. I just needed to set an option saying link relative to the doc rather than the root.
Although, I don't know why the root option wouldnt work. Why wouldn't te images folder be addressable from the root of the app?
I'm also a bit worried about how linking might work when my pages get further and further down the file system. I just have a nasty feeling that something will go wrong
Anyway, things are sort of working now even if I dont understand why they weren't before
Thanks
Simon
 
Ranch Hand
Posts: 2379
MySQL Database Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I use getServletContext().getRealPath("dirname/fileName") when I need to manipulate files within my web applications.
 
Author and all-around good cowpoke
Posts: 13078
6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I like to use the very handy "base" HTML tag - inserted in the "head" area of a page it tells the browser a base URL to request resources from.
Works for CSS, image, etc. resources.
Bill
 
Ron Newman
Ranch Hand
Posts: 1056
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I don't know anything about Dreamweaver. If it's doing the wrong thing, don't use it.
 
Ron Newman
Ranch Hand
Posts: 1056
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
If the relative address begins with "/", the browser interprets it to mean "relative to the root of the server" -- the whole server, not just your webapp.
If the relative address doesn't begin with "/", the browser interprets it to mean "relative to the URL of this page".
 
Ron Newman
Ranch Hand
Posts: 1056
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

I use getServletContext().getRealPath("dirname/fileName") when I need to manipulate files within my web applications.


But in this case, the web app isn't manipulating a file -- it just needs to generate a valid relative URL that the browser will interpret correctly.
[ July 19, 2003: Message edited by: Ron Newman ]
 
Simon Harvey
Ranch Hand
Posts: 79
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thank guys!

Simon
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic