• 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
  • Tim Cooke
  • paul wheaton
  • Jeanne Boyarsky
  • Ron McLeod
Sheriffs:
  • Paul Clapham
  • Liutauras Vilda
  • Devaka Cooray
Saloon Keepers:
  • Tim Holloway
  • Roland Mueller
Bartenders:

Linking External CSS in a JSP page

 
Greenhorn
Posts: 19
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi, I'm having a problem linking to an external CSS file in JSP. I'm simply using the following line of code, but it isn't working:

<link href="style.css" type="text/css" rel="stylesheet" />

Is there something else I need to be doing?

Thanks!
 
Sheriff
Posts: 67753
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
The href in your link element specifes a URL-relative path that will only work if the css file is in the same folder as the JSP and if the JSP is directly addressed. Since in most web apps neither of these are the case, you need to use server-relative addressing for the files.

Let's say that the css files is in a folder named styles at the context root. Adressing it would be:


<link href="${pageContext.request.contextPath}/styles/mycss.css" ...



(assuming JSP 2.0)
 
Time is mother nature's way of keeping everything from happening at once. And this is a tiny ad:
We need your help - Coderanch server fundraiser
https://coderanch.com/wiki/782867/Coderanch-server-fundraiser
reply
    Bookmark Topic Watch Topic
  • New Topic