Win a copy of Functional Reactive Programming this week in the Other Languages forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

problem loading javascript when returning jsp from controller

 
Andrew Cane
Ranch Hand
Posts: 91
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Use context path. ex: src="<%=request.getContextPath()%>/WEB-INF/files/myjs.js"
 
Carol Enderlin
drifter
Ranch Hand
Posts: 1364
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic