tags:

views:

23

answers:

2

Ok. So the problem is here..

on this address i have this url: _http://localhost/blog

img src='image/b.jpg'

and everything goes fine.. because i have my image in "image" folder... browser asking image with this url "_http://localhost/image/b.jpg"

but if i got to: _http://locahost/blog/otherfolder/

then browser start looking for "_http://localhost/blog/image/b.jpg"

I know why this happen. But i only want to know is there a way to set "universal" relative url? That ignore folders and relative to host? By plain HTML

Something like ".. src='{host}/image/b.jpg' .."

+4  A: 
 <img src='/image/b.jpg' />
Thilo
OMG. Thanks. I think i'm just hadn't sleep enough.
Ai_boy
A: 

Yeah this is a bit of broken-ness in the web. I mean I am writing JSP tags, and either

  • they write absolute URLs (which requires them to know a bit too much; our URLs are composed of a number of parts which those JSP tags wouldn't really need to know as they navigate only within one section.. i.e. the left part of the URL, beyond a certain point, is always constant... without wanting to bore you with the details..)
  • they write relative URLs which means they can only be used in one "level" of the URL structure (we have pages like /folder1/folder2/page3 etc and those tags can be used anywhere, so that won't work)

So we go with absolute URLs, but it's not ideal.

Not that, if I were designing the web, I would have a better way to do it ....

Adrian Smith
Yes, those are the two "easy" options. One could prefix with `${contextPath}` (from servlet context) to get it right. There must be a taglib for that...
Thilo
No, the left part of the URL is much more than just the context path. I don't want to go into too many details of the app but it's some complex stuff, two or three levels of the URL which comes our app. It's about a screen of code to generate it.
Adrian Smith