aspose file tools*
The moose likes IDEs, Version Control and other tools and the fly likes How to access a java script file in my jsp while rnning through eclipse Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of The Java EE 7 Tutorial Volume 1 or Volume 2 this week in the Java EE forum
or jQuery UI in Action in the JavaScript forum!
JavaRanch » Java Forums » Engineering » IDEs, Version Control and other tools
Bookmark "How to access a java script file in my jsp while rnning through eclipse" Watch "How to access a java script file in my jsp while rnning through eclipse" New topic
Author

How to access a java script file in my jsp while rnning through eclipse

Adam Zedan
Ranch Hand

Joined: Jun 10, 2011
Posts: 124

Hi i wanted to know which path should i place my javascript file so that my jsp could access it ??
FireFox gave me this error
[07:03:42.319] GET http://localhost:8080/Grid_Sample/editablegrid-1.0.11.js [HTTP/1.1 404 Not Found 2ms]
I tried placing the.js file rite next to my jsp but still i got this error ?? Any suggestions on what the path should be ??
I am using eclipse and i also run and test my jsp files through eclipse

Don’t look where you fall, but where you slipped
Peter Johnson
author
Bartender

Joined: May 14, 2008
Posts: 5823
    
    7

What kind of Eclipse project did you create? A Dynamic Web Web Application Project? If so, place the .js file in the WebContent folder.


JBoss In Action
Adam Zedan
Ranch Hand

Joined: Jun 10, 2011
Posts: 124

Yeah its a dynamic webproject and I am using Tomcat.
The jsp file is in
d:\users\Adam\workspace\Grid_Test\Webcontent\result.jsp

I placed the javascript file called editablegrid-1.0.11.js next to result.jsp ie
d:\users\Adam\workspace\Grid_Test\Webcontent\editablegrid-1.0.11.js

and my jsp file is calling the javascrip file using


but still firefox gives me



any ideas why ??? same thing with my .css files ?? I am a bit confused about the location.. Any suggestion would be appreciated..

Adam Zedan
Ranch Hand

Joined: Jun 10, 2011
Posts: 124

Okay i did a little experimentation and i came up with the following. If i place the file directly in the webcontent folder using windows explorer it doesnt work.
But if i copy the file and goto the Javascript Resources section of eclipse and paste it there then eclipse pastes a copy of the file in the webcontent folder itself and at the same time imports a list of all the functions in the file.
Now is there any way to just specify a path instead of pasting all the time and how would i link css files ??
Peter Johnson
author
Bartender

Joined: May 14, 2008
Posts: 5823
    
    7

By placing the file there in Explorer, Eclipse was not aware of its existence. Therefore, it never copied the .js file over to the deployed WAR. You need to inform Eclipse that the file is there. You can do it either the way you said (copy into Eclipse) or after copying via Explorer, hit F5 to refresh your project.

Moral of the story: if the file does not show up in the package view in Eclipse, the file does not exist within your project!

Your files, including CSS, must all be in the WebContent directory. Actually, they really just need to be in the deployed WAR file. So if you don't want to copy those files into your project, you should look into using a build tool such as Ant or Maven to build the WAR.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: How to access a java script file in my jsp while rnning through eclipse