I have folder hierarchy like this
how to add css and js file in this index.jsp
browser developer tools
I have folder hierarchy like this
how to add css and js file in this index.jsp
browser developer tools
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.
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.
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" />