473,396 Members | 1,814 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

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 25989
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
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
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
by: howa | last post by:
Hi, Consider a simple example, e.g. var a = { 'a': 'b', 'c': 'd' }
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
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...

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.