This week's book giveaway is in the Programmer Certification forum.
We're giving away four copies of OCP Oracle Certified Professional Java SE 21 Developer (Exam 1Z0-830) Java SE 17 Developer (Exam 1Z0-829) Programmer’s Guide and have Khalid Mughal and Vasily Strelnikov on-line!
See this thread for details.
  • 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 wheaton
  • Ron McLeod
  • Devaka Cooray
Sheriffs:
  • Jeanne Boyarsky
  • Liutauras Vilda
  • Paul Clapham
Saloon Keepers:
  • Tim Holloway
  • Carey Brown
  • Piet Souris
Bartenders:

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: 67754
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: 67754
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.
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic