• 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 all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Paul Clapham
  • Bear Bibeault
  • Junilu Lacar
Sheriffs:
  • Jeanne Boyarsky
  • Tim Cooke
  • Henry Wong
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • salvin francis
  • Frits Walraven
Bartenders:
  • Scott Selikoff
  • Piet Souris
  • Carey Brown

urls for css, javascript, common headers

 
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
 
Marshal
Posts: 67451
173
Mac Mac OS X IntelliJ IDE jQuery Java
  • 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 ]
 
Bartender
Posts: 1845
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
Marshal
Posts: 67451
173
Mac Mac OS X IntelliJ IDE jQuery Java
  • 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
Marshal
Posts: 67451
173
Mac Mac OS X IntelliJ IDE jQuery Java
  • 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).
 
Just the other day, I was thinking ... about this tiny ad:
the value of filler advertising in 2020
https://coderanch.com/t/730886/filler-advertising
    Bookmark Topic Watch Topic
  • New Topic