Solved

How to link css file in JSP ?

Posted on 2011-09-05
14
1,252 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

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

For beginner Java programmers or at least those new to the Eclipse IDE, the following tutorial will show some (four) ways in which you can import your Java projects to your Eclipse workbench. Introduction While learning Java can be done with…
International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
Viewers learn about the “for” loop and how it works in Java. By comparing it to the while loop learned before, viewers can make the transition easily. You will learn about the formatting of the for loop as we write a program that prints even numbers…
Viewers learn how to read error messages and identify possible mistakes that could cause hours of frustration. Coding is as much about debugging your code as it is about writing it. Define Error Message: Line Numbers: Type of Error: Break Down…

809 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