473,378 Members | 1,377 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,378 software developers and data experts.

how to pass value from javascript to java in jsp

Hi

in JSP, it's easy to pass value from java-variable to
javascript-variable, like

js_function(a)
{ a=<%java-class.A%>
}

I'm wondering how is the other way around? I tried

js_function(a)
{ <%java-class.A=%>a
}

but there was compiling error.

Can any one help?

--
Thanks
John
Toronto

Jul 23 '05 #1
3 32762
You can only pass from JSP to JS in your code. If you want to pass
variables the other way around then you'll have to use the POST or GET
method, because JSP is serverside and JS clientside, which means that
first, on the server, JSP is executed (it generates HTML and other
clientside code, like PHP does) and second, that the generated source
document is sent to the client where possible scripting languages like
JS and VBS are executed.

Hope that helps.

Cheers,
Yereth

Jul 23 '05 #2
"john woo" <jo******@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 - lr*@hotpop.com
DHTML Death Colors: <URL:http://www.infimum.dk/HTML/rasterTriangleDOM.html>
'Faith without judgement merely degrades the spirit divine.'
Jul 23 '05 #3
Yereth wrote:
You can only pass from JSP to JS in your code. If you want to pass
variables the other way around then you'll have to use the POST or
GET method, because JSP is serverside and JS clientside, [...]


The JS is probably client-side *here*.
PointedEars
--
Bill Gates isn't the devil -- Satan made sure hell
_worked_ before he opened it to the damned ...
Jul 23 '05 #4

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

Similar topics

13
by: Al Franz | last post by:
Anyone understand how to pass parameters to a JavaScript. If anyone finds this easy to do maybe they could take a look at my short script on this page and show me how it needs to be changed. ...
4
by: Sunny | last post by:
Hi, I am at present working on a jsp page which has a single text field. Upon entering a value in the field, i am trigerring an onChangeEvent() which calls a method of javascript. I am also...
2
by: umashd | last post by:
Hi, I am doing a web based project for my graduation. I studied bit of java for backend processesing and javascript for the client. Here is the scenario. In the FORM, I use INPUT TYPE=text...
10
by: Sean Dockery | last post by:
I have the following HTML file that I've been using for testing... <html> <head> <script type="text/javascript"> <!-- function handleWindowLoad() { var items = ; for (var i = 0; i < 11; i++)...
3
by: Boki | last post by:
Hi, Could you please advice, can javascript accept this kind of code? function resone(cnt) { alert("document.all.txt_note"+cnt) // cnt is the textbox index
1
by: praveenit | last post by:
hi, I am writing a small java script code where , when the textbox is clicked a pop up window is opened . on entering some data in the text area present in pop up window and pressing ''save"...
10
by: Robert Dailey | last post by:
Hi, I noticed in Python all function parameters seem to be passed by reference. This means that when I modify the value of a variable of a function, the value of the variable externally from the...
10
by: mike4722 | last post by:
I wish to have the form to be able to automatically select the radio button based on the logic of HTML/php variable. example show below: javascript: function autoForm(value) { var myForm =...
1
by: kkshansid | last post by:
i want to pass both variables($q1 and value of select) from this php page to java script so that i can get both variables in second php file srt.php <script type="text/javascript"...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
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...

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.