This week's giveaway is in the Android forum.
We're giving away four copies of Android Security Essentials Live Lessons and have Godfrey Nolan on-line!
See this thread for details.
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


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
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: 60789
    
  65

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]
 
Don't get me started about those stupid light bulbs.
 
subject: Linking External CSS in a JSP page
 
Similar Threads
netbeans does not refresh the css
JSF - Problems with NetBeans 6.9.1
Speed of JSF
layout and multibrowser hell
Activex xmldom nightmare