Latest Tutorials| Questions and Answers|Ask Questions?|Site Map



Home Jsp JSP Variable in Javascript

Related Tutorials


 
 

Share on Google+Share on Google+

JSP Variable in Javascript

Advertisement
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:

Advertisement

If you enjoyed this post then why not add us on Google+? Add us to your Circles



Liked it!  Share this Tutorial


Follow us on Twitter, or add us on Facebook or Google Plus to keep you updated with the recent trends of Java and other open source platforms.

Posted on: May 24, 2009

Related Tutorials

Discuss: JSP Variable in Javascript   View All Comments

Post your Comment


Your Name (*) :
Your Email :
Subject (*):
Your Comment (*):
  Reload Image
 
 
Comments:7
anhtuank7c
September 7, 2011
In other case ...

i want to get value of one variable from javascript to java. ex : <script type="text/javascript"> function rating(val) { var val=1; } </script> <% String a = val; <====== "How to get val value" %>
prakash
October 20, 2011
thanks

roseindia gives us the exact result, what we are searching
siddharth
March 19, 2013
thankyou

thankyou it is workign
abiraj
February 28, 2012
JSP to Javascript

it doesnot work in jquery. here is what i have been trying to do.. $(document).ready(function(){ var msg = "<%=message %>"; msg += "\nDo you wish to continue?"; var cont = confirm(msg); }); if gives null in the diaglog box.
shashi uniyal
June 6, 2012
how to store java Array in javascript array

how to store java Array in javascript array
jasper
October 4, 2012
java script

i need full of topic in jsp
Karen
November 28, 2012
Thank you!!

Very useful information =D
DMCA.com