• 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

Declaring Links in HTML / JSP pages

 
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I seem to recall a discussion in this forum some time ago describing a better way to declare URLs in <link> and <script> tags. I believe it described how to declare the URLs relative to the web application root? I have always used relative URLS, e.g. "../css/style.css" simply because it has been easy to do. However, now I have a JSP page that may be invoked via different URL mappings, e.g. /1/2 and /1/2/3. If I use relative URLS, one mapping will not work. My web application folder structure is standard RAD 7 / WebSphere 6, i.e:

WebContent/css
WebContent/js
etc.

Is there a way to declare the CSS links so that they will work for all mappings?
 
Ranch Hand
Posts: 2458
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Make use of the <base> element in the HTML head. All relative URL's in the page will be relative to it then.
 
Sheriff
Posts: 67748
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
Or, use <c:url> to form your URLs. Or, see the JSP FAQ for info on how to generate server-relative URLs.

All these approaches have their pros and cons, but the page-relative URLs you have been using are obviously not going to work.
 
James Davidson
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks Bear. I found what I was looking for in the FAQ. What I remember was something similar to the following; I just couldn't find it.

Bauke, I'll look into the <base> element. I am unfamiliar with it Thanks!
 
Bear Bibeault
Sheriff
Posts: 67748
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 should update to using JSTL and El as opposed to scriptlets and scriptlet expressions.
 
The overall mission is to change the world. When you've done that, then you can read this tiny ad:
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic