aspose file tools*
The moose likes JSP and the fly likes Linking External CSS in a JSP page Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » JSP
Bookmark "Linking External CSS in a JSP page" Watch "Linking External CSS in a JSP page" New topic
Author

Linking External CSS in a JSP page

Paul Hoffman
Greenhorn

Joined: Nov 04, 2005
Posts: 19
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

Joined: Jan 10, 2002
Posts: 61202
    
  66

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)


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Linking External CSS in a JSP page