Reputation: 299
I have the following folder structure in my project.
> src/
>>main/
>>>webapp/
>>>>WEB_INF/
>>>>>pages/
>>>>>>js/
All my script files are located in js folder and my jsp page is located in pages folder.In order to include abc.js script in my jsp page I wrote the following line
<script type="text/javascript" src="/WEB-INF/pages/js/abc.js"></script>
But I got following error
"NetworkError: 404 Not Found - http://localhost:8080/WEB-INF/pages/js/abc.js"
I am using jetty server to deploy my project. For running it I am using
mvn jetty:run
If I am putting my script file directly in webapp folder and including script in following way then it is working perfectly fine.
<script type="text/javascript" src="abc.js"></script>
But I want to maintain folder structure of my project by putting all scripts in js folder. Can somebody please tell me why jetty server is taking files located only in webapp folder? I am using windows7
Upvotes: 1
Views: 7343
Reputation: 181270
Your src
is incorrect. Java Servlet specifications states explicitly that no document under WEB-INF
directory will be available to the webserver. You need to place your JavaScript file outside of it.
Usually, you place jsp files inside of it, because they're not accessed directly. They're accessed through a Servlet or any other web development framework in Java.
If you want to maintain your folder structure, just put your js folder on the web archive root:
webapp/
js
WEB-INF/
classes/
lib/
pages/
web-xml
WEB-INF
directory was designed exactly to prevent that users could access files they should not get access to, such as classes
, lib
directories, or web.xml
deployment descriptor.
Upvotes: 1