Entry
how do I reference a Java bean with JavaScript where the bean has been declared in a JSP
Apr 6th, 2008 19:35
ha mo, Mark Pratt, Peter Whittaker,
I hope this is the answer you are looking for : the question isn't
clear to me.
The short answer is "You Can't" - the long answer goes like this.
A JSP, "Java Server Page", can basically be thought of as a HTML page
with embedded "bits of Java". When a client (a user with a web browser)
requests this JSP page for the first time, the JSP is compiled into a
JAVA Servlet. This JAVA servlet then "spits out" a static HTML page to
be displayed to the user. All objects including beans are only
available as this JAVA Servlet runs on the web server and creates the
HTML. They are not available on the client machine at all.
If you wish to extract a value from one of your beans and make it
available to Javascript do something like this:
<script language="Javascript">
var myValueExtractedFromMyBean = "<%myBean.getMyValue()%>" ;
</script>
as this arrives in your web page you will then have:
<script language="Javascript">
var myValueExtractedFromMyBean = "someValue" ;
</script>
Hope this helps,
Mark
http://www.businessian.com
http://www.computerstan.com
http://www.financestan.com
http://www.healthstan.com
http://www.internetstan.com
http://www.moneyenews.com
http://www.technologystan.com
http://www.zobab.com
http://www.healthinhealth.com