passing variables between javascript and JSP

i have a variable in jsp named "var" and i would like to assign to it a value from a java script .

How could i do this?

here is the code

<%

String var="firstletter"+ %><script>ar['0']</script><% +"the last letter";

%>

where ar['0'] is a java script array read from a java script file included as

<script src='ar1.js'>

</script>

in the header of the JSP

thanks in advance

[496 byte] By [iman_m_f] at [2007-9-18]
# 1
No I think still there is no method that can communicate between JSP and javaScript only we can communicate between Applet and JavaScript yet by using Netscape's live connect.
aqb75 at 2007-7-4 > top of java,Enterprise & Remote Computing,Web Tier APIs...
# 2

Hi,

If you want to assign the value from javascript to jsp, either you have to pass that value to jsp or you have to put that value in httpsession. For this situation you have to pass that javascript value to jsp and use it .

Hope that helps.

Best Luck,

Senthil Babu

Developer Technical Support

SUN Microsystems

http://www.sun.com/developers/support/

jsenthilbabu_indts at 2007-7-4 > top of java,Enterprise & Remote Computing,Web Tier APIs...
# 3
hiThanks for your reply "For this situation you have to pass that javascript value to jsp and use it ."But the idea is HOW to pass that javascript value to jsp?I don't know the syntax ..thanks again.
iman_m_f at 2007-7-4 > top of java,Enterprise & Remote Computing,Web Tier APIs...
# 4
you can give it a try by sending jsp variables to javascriptex.<%jsp_variables=rs.getthing("whatever");%><script>var js_variables;if(js_variables==<%=jsp_variables%>){..}</script>
tyapsing at 2007-7-4 > top of java,Enterprise & Remote Computing,Web Tier APIs...
# 5

> you can give it a try by sending jsp variables to

> javascript

>

> ex.

> <%

&gt; jsp_variables=rs.getthing("whatever");

&gt; %>

> <script>

> var js_variables;

> if(js_variables==<%=jsp_variables%>){

> .

> .

> }

> </script>

This is axactley what I do. Pass it like that.

ageresystems at 2007-7-4 > top of java,Enterprise & Remote Computing,Web Tier APIs...
# 6
you must have the script in the .jsp file. works like html
tyapsing at 2007-7-4 > top of java,Enterprise & Remote Computing,Web Tier APIs...