faqts : Computers : Programming : Languages : JavaScript

+ Search
Add Entry AlertManage Folder Edit Entry Add page to http://del.icio.us/
Did You Find This Entry Useful?

26 of 43 people (60%) answered Yes
Recently 4 of 10 people (40%) answered Yes


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()%>" ;
as this arrives in your web page you will then have:
<script language="Javascript">
var myValueExtractedFromMyBean = "someValue" ;
Hope this helps,