• Post Reply Bookmark Topic Watch Topic
  • New Topic

urls for css, javascript, common headers  RSS feed

 
Clifford Adams
Ranch Hand
Posts: 50
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I've seen guides for including common page elements using ${pageContext.request.contextPath} or c:url or html:rewrite but these all seem to make links context-relative. What if I want to import something from the root folder of my web server.

For example, I'm using apache + websphere with a plugin, so an app called MyApp can be referenced like so:

http://intranet/MyApp

What if I want to include a css file located at /css/common.css in the apache htdocs folder? I'm using absolute url's now (full http://intranet/css/common.css) , but I assume this causes several seperate connections to the apache server.

What is the best way to do this?

Thanks
 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 66208
151
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You seem to be mixing the concepts of server-releatove URLs and context-relative URLs.

All HTML references (images, css styles sheets, and the like) require either absolute refs or server-relative refs.

Internal refs (non-HTML) such as includes, require a context-relative reference.
[ March 13, 2006: Message edited by: Bear Bibeault ]
 
Clifford Adams
Ranch Hand
Posts: 50
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks for the reply.

So a server-relative url would be /css/common.css

but if I use this path in a c:include or c:url I get a path of /MyApp/css/common.css which does not exist.
[ March 13, 2006: Message edited by: Clifford Adams ]
 
Stefan Evans
Bartender
Posts: 1836
10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
>but if I use this path in a c:include or c:url I get a path of /MyApp/css/common.css which does not exist.

So don't use those tags.
The point of those tags is that they make your life easier by adding in the context prefix for you automagically. 99% of the time this is what you want.
I would just go with importing it straight:
<link href="/css/common.css" rel="stylesheet" type="text/css">

However this does make your app dependant on the style sheet being present.
 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 66208
151
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Clifford Adams:

So a server-relative url would be /css/common.css


No. That's a context-relative URL. Server-relative URLs include the context path.

Are you saying the CSS file is not part of the webb app? And therefore doesn't warrant the context path?

If so, why?
 
Clifford Adams
Ranch Hand
Posts: 50
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Bear Bibeault:



Are you saying the CSS file is not part of the webb app? And therefore doesn't warrant the context path?

If so, why?


That's correct. The css is part of the website, not just this app. I did it so I wouldn't have multiple copies of the same css in each app that would need to be updated separately. and multiple copies of the header and footer as well.
 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 66208
151
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Not making the CSS file part of the web app is something I would never do. I can understand not wanting multiple copies of a file, but that's something easily managed with a build tool like Ant rather than subverting the structure of the web application (which at best should be completely self-contained).
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!