wood burning stoves 2.0*
The moose likes Spring and the fly likes problem loading javascript when returning jsp from controller Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Frameworks » Spring
Bookmark "problem loading javascript when returning jsp from controller" Watch "problem loading javascript when returning jsp from controller" New topic
Author

problem loading javascript when returning jsp from controller

Andrew Cane
Ranch Hand

Joined: Aug 07, 2013
Posts: 91
my controller:


my jsp:


the jsp was displayed just fine, but couldn't load myjs.js. How do I solve this? thanks
umamaheswara rao akasam
Greenhorn

Joined: Apr 14, 2008
Posts: 2
Use context path. ex: src="<%=request.getContextPath()%>/WEB-INF/files/myjs.js"
Carol Enderlin
drifter
Ranch Hand

Joined: Oct 10, 2000
Posts: 1364
Move the javascript file outside of WEB-INF, files inside WEB-INF are not accessible by URL (such as the script tag).

From the servlet 2.5 spec
A special directory exists within the application hierarchy named “WEB-INF”.
This directory contains all things related to the application that aren’t in the
document root of the application. The WEB-INF node is not part of the public
document tree of the application. No file contained in the WEB-INF directory may
be served directly to a client by the container.
However, the contents of the WEBINF
directory are visible to servlet code using the getResource and getResource-
AsStream method calls on the ServletContext, and may be exposed using the
RequestDispatcher calls.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: problem loading javascript when returning jsp from controller
 
Similar Threads
JSP + Spring + Ajax
how to call javascript function from jsf
Problem Executing example of Jquery for Dummies
toggling between two languages
Ajax in Spring MVC