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...
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.
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>
1. Project Directory. A standard Maven folder structure, puts the static resources like js and css files into the webapp\resources folder.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With