Home Jsp JSP Variable in Javascript



JSP Variable in Javascript
Posted on: May 24, 2009 at 12:00 AM
JSP Variable in Javascript helps you to pass jsp variable to javascript.

JSP Variable in Javascript

        

JSP Variable in Javascript helps you to pass jsp variable to javascript. The JavaScript include a function that takes the defined variable from the jsp expression and display the message from variable using alert box.

Understand with Example 

In this section, we are going to pass the jsp variable to javascript. You can see in the given example that we have create a function access() which accept the defined variable from the jsp expression "HelloWorld". The expression <%=str%> is used to insert the jsp variable values directly into the output. This  will display the value of string variable using the alertbox on loading the function.

 

 

 

Here is the code of passJspvariable.jsp

<html> 
<head>
<script language="javascript"> 
function access(){ 
<% String str="Hello World"; %>
var s="<%=str%>"; 
alert(s); 

</script> 
</head> 
<body onload="access()"> 
</body> 
</html>

Output will be displayed as:

Download Source Code:

Related Tags for JSP Variable in Javascript:
javajavascriptcjspfunctionscriptfunioincludevariabledisplayipexpressionusingriamessagejsdefinealertuncboxexpressssiesplvarfrominasmplaysagejispclesfuncagemedefinedsssaspessatkincishapresspreandarrtsaxpvascrssriripthavabablhatdispfinplprndonomo


More Tutorials from this section

Ask Questions?    Discuss: JSP Variable in Javascript   View All Comments

Post your Comment


Your Name (*) :
Your Email :
Subject (*):
Your Comment (*):
  Reload Image
 
 

Ask Questions?

If you are facing any programming issue, such as compilation errors or not able to find the code you are looking for.

Ask your questions, our development team will try to give answers to your questions.