1

I have css files under css folder and jsp files under jsp folder and both folders are inside WEB-INF folder. So how can i get the css file inside jsp?

  <link rel="stylesheet" href="../css/style.css>

I have given path like this.

7
  • 2
    Look at console and check if you got 404 Commented Mar 12, 2013 at 8:46
  • 6
    The closing quote is missing for href, can you try after adding that? Commented Mar 12, 2013 at 8:47
  • 1
    @vivek I assume you meant "closing quote"? Commented Mar 12, 2013 at 8:49
  • 2
    have to remove everything before css. It should be like href="css/style.css". Commented Mar 12, 2013 at 8:51
  • 1
    @TiesonT. Yeah, I meant the same. Edited the comment. Thanks! Commented Mar 12, 2013 at 8:51

5 Answers 5

15

Try to use this:

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

instead of

href="../css/style.css

Here you are missing right apostrophe. Also check BalusC answer would solve your problem.

Note:

Also i recommend to you create resources folder on the same level as WEB-INF then in resources folder create css folder and then reference css file as:

WEB-INF
resources
  --css
    --styles.css
  --js
    --scripts.js 

and here how to connect css with page:

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

I'm using this approach is my web project and everything works correctly.

Sign up to request clarification or add additional context in comments.

1 Comment

Thank you. It didn't work for me until I've put this: rel="stylesheet"
4

The @import rule is another way of loading a CSS file:

<style>
    @import url('/css/styles.css');
</style>

you can import all the styles at the same time using this trick, like:-

@import url('/css/header.css') screen;
@import url('/css/content.css') screen;
@import url('/css/sidebar.css') screen;
@import url('/css/print.css') print;

Comments

1

Under a previous version of HTML, to reference an external css file in a another folder, the href attribute required the actual file path such as href="./CSS/filename.css" Using HTML5, I have my css files in a sub-folder and to my amazement, the above approach doesn't work which I could not understand. I remove the dot at the beginning, that didn't work. Then I remove the stating slash(/), again it didn't work. It seems HTML5 only requires the actual css file name to work. So even with the css file in a sub-folder href="filename.css" works!

Comments

0

In case if the above answers didn't solve your problem.you can access the file by mentioning its full address.It's always better to add the full file path instead of messing around with the Forward slash.

<link rel="stylesheet"  href="C:\bacon\WD3.5 Bacon Fansite Start Here\styles.css" >

This is the easiest way to access the External File.Just by simply copying the Full address path of the External file into the main File.But make sure that both Files should be in the Same Folder.

Comments

-4
    <%@ page language="java" contentType="text/html; charset=ISO-8859-1"
        pageEncoding="ISO-8859-1"%>
    <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
    <html>
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
      <title>Login Form</title>
      <link rel="stylesheet" type="text/css" href="css/style.css">
    </head>
 </html>

3 Comments

Would be enough this line <link rel="stylesheet" href="css/style.css">. And I believe you will accept your own answer later? :)
got it fixed ? or you just want to add your code you could have edited the question itself.
@Morpheus hahahaha interesting.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.