I have a dynamic web app developed in Eclipse using Tomcat. My web application folder is WebContent which has the following structure:
WebContent
|_____WEB-INF
| |__ web.xml
|___form.html
|
|___send.js
The form.html file references the JavaScript file send.js as follows:
<script src="http://code.jquery.com/jquery-1.10.1.min.js"></script>
<script src="send.js"></script>
They are both in the same root directory of WebContent. However, when I started the servlet in Eclipse and tried opening form.html
in the browser. The send.js
is not executed. But if I copy everything in send.js
directly to form.html
and put them in the <script>...</script>
tags, it will execute the JavaScript code correctly. I don't want to put all JS code in the HTML file, so I prefer to have send.js file separate from HTML file. So how to make JS file to be executed?
Also I'm using Jersey as RESTful web service and my web.xml servlet mapping is as follows:
<servlet>
<servlet-name>Jersey REST Service</servlet-name>
<servlet-class>com.sun.jersey.spi.container.servlet.ServletContainer</servlet-class>
<init-param>
<param-name>com.sun.jersey.config.property.packages</param-name>
<param-value>com.example</param-value>
</init-param>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>Jersey REST Service</servlet-name>
<url-pattern>/rest/*</url-pattern>
</servlet-mapping>
Why can't Jersey's Servlet container find the JavaScript file (send.js
) in the web root directory (WebContent)?