Solved

How to link css file in JSP ?

Posted on 2011-09-05
14
1,244 Views
Last Modified: 2012-05-12
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
Comment
Question by:cofactor
  • 7
  • 4
  • 2
  • +1
14 Comments
 
LVL 20

Accepted Solution

by:
chaitu chaitu earned 250 total points
ID: 36482717
<link href="../../css/styles.css" type="text/css" rel="stylesheet">
0
 
LVL 47

Expert Comment

by:for_yan
ID: 36482725

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
 
LVL 20

Expert Comment

by:Sathish David Kumar N
ID: 36482779
<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
 

Author Comment

by:cofactor
ID: 36483365
>>>ur mistake is backslas  change that \ into /

No. This cant not work. You did not notice the folder structure closely.
0
 

Author Comment

by:cofactor
ID: 36483380
>>>/ur Project name

I dont want to put  Project Name there.
0
 
LVL 20

Expert Comment

by:chaitu chaitu
ID: 36483382
cofactor,

have u seen my coment
0
 

Author Comment

by:cofactor
ID: 36483392
>>>>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
DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

 
LVL 20

Expert Comment

by:Sathish David Kumar N
ID: 36483414
then use contenttype
0
 
LVL 20

Expert Comment

by:Sathish David Kumar N
ID: 36483415
>>
No. This cant not work. You did not notice the folder structure closely.

Have you tried ? without tiring your saying ?
0
 

Author Comment

by:cofactor
ID: 36483442
>>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
 
LVL 20

Expert Comment

by:Sathish David Kumar N
ID: 36483736
without puting / infront of the any folder then application will directly check in root folder only
0
 

Author Comment

by:cofactor
ID: 36483898
>>>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
 

Author Comment

by:cofactor
ID: 36484002
>>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
 

Author Comment

by:cofactor
ID: 36484086
>>><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

3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Application launch issue with Apache Tomcat 5 18
firstswap challenge 20 65
Starting to learn JAVA, 7 59
Image decoding from Camera 3 72
INTRODUCTION Working with files is a moderately common task in Java.  For most projects hard coding the file names, using parameters in configuration files, or using command-line arguments is sufficient.   However, when your application has vi…
Java Flight Recorder and Java Mission Control together create a complete tool chain to continuously collect low level and detailed runtime information enabling after-the-fact incident analysis. Java Flight Recorder is a profiling and event collectio…
This tutorial covers a practical example of lazy loading technique and early loading technique in a Singleton Design Pattern.
This video teaches viewers about errors in exception handling.

929 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

17 Experts available now in Live!

Get 1:1 Help Now