• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1359
  • Last Modified:

How to link css file in JSP ?

In Eclipse Web Project I have files:

WebContent\css\style.css
WebContent\pages\life\life.jsp

How do I link style.css in life.jsp ?

This does NOT work.
<link href="css\styles.css" type="text/css" rel="stylesheet">

Could you please suggest how do I link correctly ?
0
cofactor
Asked:
cofactor
  • 7
  • 4
  • 2
  • +1
1 Solution
 
chaitu chaituCommented:
<link href="../../css/styles.css" type="text/css" rel="stylesheet">
0
 
for_yanCommented:

check this:

http://stackoverflow.com/questions/6599254/include-a-css-file-as-inline-style-in-a-jsp
      

This sort of directive should work, but you will need to be sure of the path you're using:

<%@ include file="/path_to/your_css_file.css" %>

0
 
Sathish David Kumar NCommented:
<link rel="stylesheet" type="text/css" href="/ur Project name/css/styles.css" />

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

ur mistake is backslas  change that \ into /
0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
cofactorAuthor Commented:
>>>ur mistake is backslas  change that \ into /

No. This cant not work. You did not notice the folder structure closely.
0
 
cofactorAuthor Commented:
>>>/ur Project name

I dont want to put  Project Name there.
0
 
chaitu chaituCommented:
cofactor,

have u seen my coment
0
 
cofactorAuthor Commented:
>>>>have u seen my coment

Yes. I like relative path. But can  in every page  this costs two "/" and couple of dots.  Can we make it more simpler ?
0
 
Sathish David Kumar NCommented:
then use contenttype
0
 
Sathish David Kumar NCommented:
>>
No. This cant not work. You did not notice the folder structure closely.

Have you tried ? without tiring your saying ?
0
 
cofactorAuthor Commented:
>>then use contenttype

not understood.

>>>Have you tried ? without tiring your saying ?

No.  I said because jsp lies  two folders down i.e ( "pages" , "life" ).   and  css is just under root .  So that should not work.

Do you still say that will work. how come ?
0
 
Sathish David Kumar NCommented:
without puting / infront of the any folder then application will directly check in root folder only
0
 
cofactorAuthor Commented:
>>>without puting / infront of the any folder then application will directly check in root folder only

I tried when it is in HTML ..this does not work.

Do you mean when I deploy in server as JSP, this will work ?
0
 
cofactorAuthor Commented:
>>without puting / infront of the any folder then application will directly check in root folder only
>>Do you mean when I deploy in server as JSP, this will work ?

No..neither way ....it did not work even after deployment.
0
 
cofactorAuthor Commented:
>>><link href="../../css/styles.css" type="text/css" rel="stylesheet">

This worked.  

But not happy to see two many slas and dots .
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

  • 7
  • 4
  • 2
  • +1
Tackle projects and never again get stuck behind a technical roadblock.
Join Now