• Post Reply Bookmark Topic Watch Topic
  • New Topic

Declaring Links in HTML / JSP pages

 
James Davidson
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
  • 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?
 
Bauke Scholtz
Ranch Hand
Posts: 2458
  • Mark post as helpful
  • send pies
  • 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.
 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 65522
105
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • 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
  • 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
Author and ninkuma
Marshal
Posts: 65522
105
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You should update to using JSTL and El as opposed to scriptlets and scriptlet expressions.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!