-6

I have folder hierarchy like this

enter image description here

how to add css and js file in this index.jsp

browser developer tools

enter image description here

Ayush
  • 206
  • 7
  • 22

3 Answers3

1

It all depends on the paths they will have from the browser's perspective. If the browser sees the hierarchy you've shown, then from any of the .jsp files in your jsp directory, you'd use

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

The .. goes up one level (from jsp to your root), and then /css goes into the css directory.

You could use root-relative URL like /css/filename.css, but that will break if you put this whole thing somewhere other than the root on the server.

Anshuman
  • 758
  • 7
  • 23
T.J. Crowder
  • 1,031,962
  • 187
  • 1,923
  • 1,875
1

If you want to add css and js files inside one of the jsp files, add these inside head

For CSS

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

For JS

<script src="../js/filename.js"></script>

Here .. represents the directory above the jsp (one level up) then /js or /css will goto respective directory.

Anshuman
  • 758
  • 7
  • 23
0

See this answer for the correct way to organise your files in a Tomcat application.

The path to your CSS files should be:

<link rel="stylesheet" type="text/css" href="./css/styles.css" />
Yvonne Aburrow
  • 2,602
  • 1
  • 17
  • 47
  • `href="./css/styles.css"` should be `href="../css/styles.css"` – Anshuman Oct 12 '18 at 16:34
  • See this link: https://www.bennadel.com/blog/3244-non-module-file-paths-are-relative-to-the-working-directory-in-node-js.htm it depends how the application is served. Also the OP has already said that `"../css/styles.css"` doesn't work. – Yvonne Aburrow Oct 12 '18 at 16:35