This week's book giveaways are in the Refactoring and Agile forums.
We're giving away four copies each of Re-engineering Legacy Software and Docker in Action and have the authors on-line!
See this thread and this one for details.
Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Cloud/Virtualization forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Reference java script in servlet code

 
David Perry
Greenhorn
Posts: 19
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have a servlet that generates html code to display a page back to the user. In this html code, I'm trying to place a reference to a java script file.
"<script language='javascript' src='../myscript.js'></script>"
The page gets generated, however when the user does something that calls a function in the java script, the page bombs out. The only way I can get this to work is to actually embed the java script in the html page that is sent back.
"<script language='javascript'>function submitForm(inParam){this.document.resultsform.dml.value=inParam;this.document.resultsform.submit();}</script>"
My thought was that maybe I can't embed a reference to a java script because there's no actual html page that exists and therefore no context for the java script file to be referenced to. Anyone have any experience feedback on this?
Thanks in advance.
David
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 64631
86
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Your relative reference of "../" will be relative to the current URL, which in the case of a servlet does not represent a physical folder. You need to modify the reference to be server relative.
For example, something along the lines of src="/mywebapp/scripts/myscript.js"
bear
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic