0

I have hello() javascript fuction in file1.jsp. I want to call hello() by file2.jsp. file1.jsp has

<html>
<script>
function hello()
{
...
}
</script>
</html>

I want to call this hello() function from file2.jsp

1 Answer 1

3

Perform the steps below:

Move the script in page1.jsp file to a new JavaScript file e.g. main.js file and place the file in new folder e.g. js inside your WebContent folder.

Link main.js in page1.jsp file by putting below link in the section:

/js/main.js"> Do the same in page2.jsp file.

This way, same javascript code will be available for use in both page1.jsp and page2.jsp files.

Sign up to request clarification or add additional context in comments.

1 Comment

Yes, it's always a good idea to separate your javascript code from your markup.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.