1

I would like to ask you how can I add properly jQuery library to the Spring MVC project. In src/webapp directory I have resources folder. I have created inside js directory. And then I have pasted downloaded jQuery library. But Eclipse have found a few errors and now I can't run my project. So what is the way to add and use properly jQuery library in Spring MVC project? Maybe using Maven add some dependencies in POM.xml?

I have founded this question How to include the jQuery library in a Spring-MVC Eclipse project but it haven't resolved my problem.

1
  • search for how to serve static content with spring. (mvc:resources, a different servlet, a content delivery server) You can't just throw a js in src/main/resources and think it will be included on the page.
    – G-Man
    Jul 6, 2012 at 13:12

2 Answers 2

4
<script type="text/javascript"
    src="https://ajax.googleapis.com/ajax/libs/jquery/1.7/jquery.min.js"></script>

Just put that in the head of your jsp page. From here. Or if you want to manually supply your own jquery file add this to app context (and create javascript directory in yr webapp folder obviously):

<mvc:resources location="/javascript/" mapping="/javascript/**" />

then in jsp

<c:url var="jq" value="/javascript/jquery.js" />
<script type="text/javascript" src="${jq}"></script>
3
  • Thank you very much. But when I want to supply my own jquery file still it causes errors in 'webapp/resources/js' directory.
    – woyaru
    Jul 6, 2012 at 13:43
  • change the resources defintiion in appcotnacxt to match your folder set up, don't copy mine ad verbatim Jul 6, 2012 at 13:48
  • I have of course adjusted your code to my project. However I have to look closer.
    – woyaru
    Jul 6, 2012 at 13:54
1

Use the google cdn :

<script type="text/javascript src="//ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js" ></script>

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.