I have read more than 5 related threads here, but could not the answer: step-by step instructions. Till now I have the STS Spring MVC template structure and try to put jquery.js
somewhere in my project (unfortunately, nobody says, where it should be). So, please say:
- where to place jquery.js in the project structure?
- how to refer to this location from .jsp?
- any other actions needed? like maven, app config changes?
My jsp works perfectly with http://code.jquery.com/jquery-1.8.3.js
, but refuses to work with local file /js/jquery-1.8.3.js
. And a strange thing - when jsp can not find the script, app server complaints about it, but when it (have found?) the library, no warnings, but jquery also doesn't work.
The JavaScript files are just resources that must be downloaded by the browser. So you put them where you want under the webapp root directory.
Suppose you put your file under
/js/jquery.js
(in the WebContent directory of your web project). And suppose your webapp has/myFirstWebApp
as context path. This means that the root of the webapp, once the application is deployed, will be atand that your JS file will thus be at
To generate a URL in a webapp, you typically use the
<c:url>
tag:The c:url tag takes care of the context path:it prepends it to the absolute URLs you give it in order to halp you change the context path later.
for includes, it's a better to write
The js folder should be placed under WebContent folder.
Copy the JQuery library under WebContent (like, WebContent\jquery\js\jquery-1.9.1.js is valid)
In JSP:
In spring-context.xml add: