Re: how to pass value from javascript to java in jsp
Available news archives: comp.lang.tcl - comp.lang.python - comp.security.firewalls - sci.crypt - comp.lang.php - comp.lang.javascript
Google
 
Web news.hping.org


comp.lang.javascript archive

Re: how to pass value from javascript to java in jsp

From: Lasse Reichstein Nielsen <lrn@hotpop.com>
Date: Thu Jun 23 2005 - 19:36:56 CEST

"john woo" <john_woo@canada.com> writes:

> in JSP, it's easy to pass value from java-variable to
> javascript-variable, like
>
> js_function(a)
> { a=<%java-class.A%>
> }

Notice what happens here: The java is evaluated and inserted
in something that is just text. It happens to be a Javascript
program, but the JSP template engine doesn't really care.
To the server, where this runs, it's just text and Java.
The output of the template is just text.

> I'm wondering how is the other way around? I tried
>
> js_function(a)
> { <%java-class.A=%>a
> }

The server doesn't care whether you write that or this:

 argleebargle <%java-class.A=%> glop glyf

It's still just malformed Java and random text to it.

The javascript is run on the client, i.e., in the browser. At that
time, the Java is long gone, and only the output of the template
remains. If you want to bring a value from the javascript, running
on the client, to Java, running on the server, you need to send
it to the server somehow - as part of an HTTP request.

/L

-- 
Lasse Reichstein Nielsen  -  lrn@hotpop.com
 DHTML Death Colors: <URL:http://www.infimum.dk/HTML/rasterTriangleDOM.html>
  'Faith without judgement merely degrades the spirit divine.'
Received on Tue Oct 18 02:47:57 2005