Solved

How to link css file in JSP ?

Posted on 2011-09-05
14
1,248 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
Master Your Team's Linux and Cloud Stack!

The average business loses $13.5M per year to ineffective training (per 1,000 employees). Keep ahead of the competition and combine in-person quality with online cost and flexibility by training with Linux Academy.

 

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

DevOps Toolchain Recommendations

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

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
HSSFWorkbook cannot be resolved error 10 71
couple of eclipse 5 38
how to add new optional parameter to JSP 1 42
servlet example issue 6 40
Introduction Java can be integrated with native programs using an interface called JNI(Java Native Interface). Native programs are programs which can directly run on the processor. JNI is simply a naming and calling convention so that the JVM (Java…
Go is an acronym of golang, is a programming language developed Google in 2007. Go is a new language that is mostly in the C family, with significant input from Pascal/Modula/Oberon family. Hence Go arisen as low-level language with fast compilation…
Viewers will learn about arithmetic and Boolean expressions in Java and the logical operators used to create Boolean expressions. We will cover the symbols used for arithmetic expressions and define each logical operator and how to use them in Boole…
Viewers will learn one way to get user input in Java. Introduce the Scanner object: Declare the variable that stores the user input: An example prompting the user for input: Methods you need to invoke in order to properly get  user input:

803 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