Yan Zhu wrote:
>
> Hung Yee wrote:
>
> > Javascript code on the client cannot access Java objects that were created
> > in the JSP page on the server!
> >
>
>     but I did. In fact, I have a ejb created on a totally different server, and I
> got
> the remote interface, persisted that in http session, and called it from
> javascript, and
> got the right value!

Most likely, what you really did was generate the JavaScript code in a
JSP page, and a part of the JavaScript you generated was a statement that
assigns a value to a JavaScript variable, using JSP scriptlets to get the
value from a Java object. Something like this:

  <script language="JavaScript">
    // JavaScript code
    var myVar = "<%= someSessionBean.getSomeValue() %>";
  </script>

As far as JSP is concerned, this is just template text (all the JavaScript
code) and a JSP expression. When the JSP page is processed, all template
text is sent as is to the browser, along with the result of executing the
JSP expression (on the server). The result could look like this:

  <script language="JavaScript">
    // JavaScript code
    var myVar = "foo";
  </script>

Note how the JSP expression has been replaced with the value resulting
from executing the Java code in the expression. When this response
reaches the browser, the browser executes it and myVar gets the value
"foo".

Even though it may appear that you assign the value of a a Java object directly
to a JavaScript variable, the fact is that you don't, as this example shows; you
generate parts of the JavaScript code, containing Java object values, on the
server,
and the real assignment takes place in the browser when the result is executed.
And by then, it's just a simple string assignment.

I hope this makes it clearer what's going on.

Hans
--
Hans Bergsten           [EMAIL PROTECTED]
Gefion Software         http://www.gefionsoftware.com
Author of JavaServer Pages (O'Reilly), http://TheJSPBook.com

===========================================================================
To unsubscribe: mailto [EMAIL PROTECTED] with body: "signoff JSP-INTEREST".
For digest: mailto [EMAIL PROTECTED] with body: "set JSP-INTEREST DIGEST".
Some relevant FAQs on JSP/Servlets can be found at:

 http://java.sun.com/products/jsp/faq.html
 http://www.esperanto.org.nz/jsp/jspfaq.html
 http://www.jguru.com/jguru/faq/faqpage.jsp?name=JSP
 http://www.jguru.com/jguru/faq/faqpage.jsp?name=Servlets

Reply via email to