Skip to content
Advertisement

JSP doesn’t see CSS and JS files from resources folder

I have some problem with my css and js import in my web application. I am using Servlets/JSP/CSS/JS.

I am sorry for this question, i saw many questions and answers for this theme and situation but nothing helped me.

I am trying to add css and js files like this:

JavaScript

But something happends and all of my css and js files doesn’t work. My folders/files positions in the project:

enter image description here

I had tried many different ways to terminate that issue. I tried this: https://stackoverflow.com/a/23687360/5331196 and https://stackoverflow.com/a/29012643/5331196

And nothing helped me. But the only thing which is working is dinamyc import: <%@include file="/resources/stylesheet/login.css" %> e.t.c.

It helped, but, in that case, there will be a lot of code in my jsp page because my .css and .js files are huge.

What should i do to terminate that issue and how can i do that static import in this situation?

Thanks to all,who can answer, your friend, davakin111.

My web.xml file:

JavaScript

Advertisement

Answer

For JSP project:

Create cssLoader.jsp page inside folder webapp as below:

JavaScript

cssLoader.jsp

JavaScript

Then load this cssLoader page where you want to import css/js file in page using <jsp:include page="../../cssLoader.jsp"></jsp:include>. For example: in my case DIRECTORY:

JavaScript

page.jsp

JavaScript

Note:

../../ depends upon folder level structure.

User contributions licensed under: CC BY-SA
10 People found this is helpful
Advertisement