473,502 Members | 8,125 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

assign JavaScript variable to Java variable problem in JSP

If I assign Java variable a to javascript variable x, it is
fine.
<%
int a = 10;
%>
var x = <%= a %>;
alert(x);

But if I do the other way around, then it has 500 error. any ideas??

<%
int b;
%>
<% b %> = x;
thanks!
Jul 23 '05 #1
2 25997
Matt wrote:
If I assign Java variable a to javascript variable x, it is
fine.
<%
int a = 10;
%>
var x = <%= a %>;
alert(x);

But if I do the other way around, then it has 500 error.
any ideas??

<%
int b;
%>
<% b %> = x;


With server-side scripting one of the most fundamental things that needs
to be grasped is what runs where and when. The approximate process
goes:-

1. Browser sends a request to a server.
2. Server discovers that the request is for a JSP
and *executes* the method of that JSP that builds
a response (usually HTML page source code that may
include client-side javascript).
3. The response is sent back to the browser.
4. The browser receives the response and displays the
result, executing any javascript that may be included.

As a result the JSP should be considered to have finished before the
javascript has even started. The JSP, executing first, may write values
into any javascript source code on the page but the only way a
client-side javascript variable value is going to get anywhere near a
JSP is if it is sent back as part of a query string on a GET request or
as part of a POST request.

Richard.
Jul 23 '05 #2
Since Java runs on the server, and javascript waits until it gets to the
browser, Java does not know what the value of the javascript variable is. It
don't work now, and it won't work - unless you include a var's value in the
querystring you send to the jsp.

"Matt" <jr********@hotmail.com> wrote in message
news:ba**************************@posting.google.c om...
If I assign Java variable a to javascript variable x, it is
fine.
<%
int a = 10;
%>
var x = <%= a %>;
alert(x);

But if I do the other way around, then it has 500 error. any ideas??

<%
int b;
%>
<% b %> = x;
thanks!

---
Outgoing mail is certified Virus Free.
Checked by AVG anti-virus system (http://www.grisoft.com).
Version: 6.0.769 / Virus Database: 516 - Release Date: 9/25/2004
Jul 23 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

16
25390
by: sneill | last post by:
How is it possible to take the value of a variable (in this case, MODE_CREATE, MODE_UPDATE, etc) and use that as an object property name? In the following example I want 'oIcon' object to have...
8
7379
by: Sergei | last post by:
Hi, I am displaying modal dialog and passing values from the main form to the modal dialog and back. It works fine but if I used the following syntax on Page_Load(just for testing) in VB to...
5
8060
by: howa | last post by:
Hi, Consider a simple example, e.g. var a = { 'a': 'b', 'c': 'd' }
0
7302
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
7434
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
5542
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
1
4971
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
4652
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
3137
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1475
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
1
712
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
355
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.