• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 5394
  • 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
  • 2
1 Solution
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 ?
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...

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

Open in new window

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

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Train for your Pen Testing Engineer Certification

Enroll today in this bundle of courses to gain experience in the logistics of pen testing, Linux fundamentals, vulnerability assessments, detecting live systems, and more! This series, valued at $3,000, is free for Premium members, Team Accounts, and Qualified Experts.

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