views:

776

answers:

2

I am using Eclipse Ganymede and Tomcat 5.5. I would like to add some javascript and especially ajax functionality to a dynamic web project and need some help.

I would like to use jquery (but I am open to other suggestions, if you tell me why another library would be better in this case, but I have chosen jquery because it is supposed to be simple (which on the first look it seems to be)).

I am having two problems:

1- Tomcat can't find the jquery library. I tried several things in my jsp file like:

   <script type="text/javascript" src="WEB-INF/lib/jquery-1.3.2.min.js"></script>
   <script type="text/javascript" src="/WEB-INF/lib/jquery-1.3.2.min.js"></script>
   <script type="text/javascript" src="./WEB-INF/lib/jquery-1.3.2.min.js"></script>

As you can see, I threw the jquery library in /WEB-INF/lib. Executing the jsp file within a browser without tomcat (with the last path version) works, so the path is correct.

2- There is no proper syntax highlighting within the dynamic web project for jquery and no popup suggestions. I also tried the information in this article, but it didn't change much.

+1  A: 

I haven't done much with Tomcat for a while, but from this thread, it looks like you can't reference files in WEB-INF. It says to store your js files under Tomcat/webapps/myApp/

Hope it helps.

patrick dw
thanks this was really simple, don't know why i didn't see it
Red33mer
A: 

To be more specific (because it took me about half an hour to figure this out after getting to this point):

When you create a Dynamic Web Project with Tomcat in Eclipse, among other things in the project you get a folder named "WebContent". That's the actual folder that gets deployed to the Tomcat server, in Eclipse's equivalent of Tomcat/webapps/<project name> (I'm not sure where it really exists). For security reasons, as a special case nobody can access the META-INF and WEB-INF folders in there, so putting your scripts in those places will not help.

What you have to do is create a folder inside of WebContent, and stick your Javascript in there. This folder will be globally visible, so visitors to your site (like you, when you test it) can actually get to the Javascript.

What I did, for instance, was create a folder named "script" in WebContent and put my Javascript in there; then, when I needed to reference it in a page, I put in src="ProjectName/script/AwesomesauceJavascript.js"

Tacroy