Pass value from JSP to JavaScript

We can also pass the value from a JSP page to the java script as we have done in our previous example of passing values to the java script from the HTML page.

Pass value from JSP to JavaScript

We can also pass the value from a JSP page to the java script as we have done in our previous example of passing values to the java script from the HTML page.

Pass value from JSP to JavaScript

Pass value from JSP to JavaScript

     

We can also pass the value from a JSP page to the java script as we have done in our previous example of passing values to the java script from the HTML page. Since in JSP page we can embed HTML tags as well. 

In our this example of passing values from jsp page to java script we have created a function hello() which takes value from the jsp page on click of some button and then shows it through the alert().

Here is the example code of the JSP page which is passing value to the java script as follows:

PassJSP.jsp

<%page language="java" %>
 <head>
  <title>
  Pass value from JSP to JavaScript 
  </title>
  <script language="JavaScript" >
  function hello(name)
  {
  alert("Hello! "+name);
  }
  </script> 
 </head>
  Getting Message<br>
 <input type="button" onclick='hello("JSP Example");value="Click"/>

Output:

Download Source Code