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. Commented 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>
Sign up to request clarification or add additional context in comments.

3 Comments

Thank you very much. But when I want to supply my own jquery file still it causes errors in 'webapp/resources/js' directory.
change the resources defintiion in appcotnacxt to match your folder set up, don't copy mine ad verbatim
I have of course adjusted your code to my project. However I have to look closer.
1

Use the google cdn :

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

Comments

Your Answer

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

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.