Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to include the jQuery library in a Spring-MVC Eclipse project

Good day,

I have searched far and wide but all I can find is information about how to add various plugins to Eclipse. I don't want a plugin. I want my stinkin' jQuery!

Some things I've tried:

I download jQuery and put it in my WebContent\WEB-INF\js folder. Then in my WebContent\WEB-INF\jsps\company.jsp file, I have a script tag:

<script type="text/javascript" src="../js/jquery-1.4.3.min.js"></script>

But no dice. So on to the next attempt.

Window -> Preferences -> JavaScript -> Include Path -> User Libraries -> New...

Here I added my jQuery library and referened my file correctly. I can see my jQuery library in JavaScript Resources. It looks just like I'd expect it. But still, my jQuery script is not included in my page.

What am I missing here? Is this such a no-brainer that nobody bothers to properly document how to do this? If it's such a no-brainer, why can't I figure it out? I THOUGHT I had a brain...

like image 341
Samo Avatar asked Nov 09 '10 18:11

Samo


People also ask

Which jQuery library is used to do programs?

jQuery is a JavaScript library designed to simplify HTML DOM tree traversal and manipulation, as well as event handling, CSS animation, and Ajax. It is free, open-source software using the permissive MIT License. As of Aug 2022, jQuery is used by 77% of the 10 million most popular websites.

What is jQuery library file?

The jQuery library is a single JavaScript file, and you reference it with the HTML <script> tag (notice that the <script> tag should be inside the <head> section): <script src="jquery-3.6.0.min.js"></script>

Where do I put CSS files in Spring MVC?

1. Project Directory. A standard Maven folder structure, puts the static resources like js and css files into the webapp\resources folder.


1 Answers

I think you need to locate the file NOT under the WEB-INF directory, as anything there is not visible to the HTML resulting from your JSP. Try putting your js directory directly under WebContent and changing your reference in the tag accordingly.

EDIT: In response to the comment you left under Jay's answer. How are you referencing the file in your script tag?

You will probably want something like:

<script type="text/javascript" src="/<web-context-root>/js/jquery-1.4.3.min.js"></script> 

where web-context-root is specific to your application and assuming you put your js directory directly under WebContent.

like image 67
GriffeyDog Avatar answered Nov 06 '22 13:11

GriffeyDog