Win a copy of Terraform in Action this week in the Cloud forum!
  • 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:
  • Tim Cooke
  • Campbell Ritchie
  • Paul Clapham
  • Ron McLeod
  • Liutauras Vilda
Sheriffs:
  • Jeanne Boyarsky
  • Rob Spoor
  • Bear Bibeault
Saloon Keepers:
  • Jesse Silverman
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
Bartenders:
  • Piet Souris
  • Al Hobbs
  • salvin francis

urls for css, javascript, common headers

 
Ranch Hand
Posts: 50
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Sheriff
Posts: 67601
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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 ]
 
Bartender
Posts: 1845
10
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
Sheriff
Posts: 67601
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
Sheriff
Posts: 67601
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
reply
    Bookmark Topic Watch Topic
  • New Topic