File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Linking External CSS in a JSP page

 
Paul Hoffman
Greenhorn
Posts: 19
  • 0
  • Mark post as helpful
  • send pies
  • 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!
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 64205
83
IntelliJ IDE Java jQuery Mac Mac OS X
  • 0
  • Mark post as helpful
  • send pies
  • 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)
 
I agree. Here's the link: http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic