[Last Call] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 5384
  • Last Modified:

Call javascript from jsp

Hello Everyone,

I have a jsp page which acts as a template in the main page, the jsp page does not have any body tags,I want to call a javascript function within this jsp page whenever the page is loaded or refreshed. Usually in a html body tag you could call it in the onLoad event, how would i call it without the body tag.

Thank you
Harsha
0
gbvreddy
Asked:
gbvreddy
  • 2
1 Solution
 
rrzCommented:
What does the javascript do ?  
>how would i call it without the body tag.  
Doesn't the JSP output ultimately end up in the body tag of the enclosing page ?
0
 
TimYatesCommented:
You could try just sticking the javascript at the bottom of your template...  Then the full DOM won't have finished loading, but at least this part of it will have...

<div>
  <%= "Woo! I'm a JSP with no body" %>
</div>
<script type="text/javascript">
  alert( 'and I'm some javascript' );
</script>

Open in new window

0
 
TimYatesCommented:
(obviously, you should use valid javascript with no escaping errors like mine)

*blush*
0

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now