Win a copy of Learn Spring Security (video course) this week in the Spring forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

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

 
Adam Zedan
Ranch Hand
Posts: 124
C++ Fedora Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
Peter Johnson
author
Bartender
Posts: 5852
7
Android Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What kind of Eclipse project did you create? A Dynamic Web Web Application Project? If so, place the .js file in the WebContent folder.
 
Adam Zedan
Ranch Hand
Posts: 124
C++ Fedora Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 124
C++ Fedora Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 5852
7
Android Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic