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.

Newb
  • 2,810
  • 3
  • 21
  • 35
sanit
  • 1,646
  • 1
  • 18
  • 21

5 Answers5

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.

Community
  • 1
  • 1
Simon Dorociak
  • 33,374
  • 10
  • 68
  • 106
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;
Ben Aston
  • 53,718
  • 65
  • 205
  • 331
Kesar Sisodiya
  • 1,564
  • 2
  • 15
  • 25
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!

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.

Prajwal KV
  • 51
  • 6
-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>
Code Disease
  • 64
  • 1
  • 3
  • 10
sanit
  • 1,646
  • 1
  • 18
  • 21