473,544 Members | 1,960 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Calling java within javascript



Hi,

I know I can call a static java method within javascript by using the
<% ... %tags. But how can pass a javascript variable ?

function thefunction()
{

var = javascriptvaria ble ;

<% testClass.set(v ar) ; %;

}
this works when i put a constant in

<% testClass.set(" iiiiiiiiii") ; %;
Thanks!

Aug 30 '06 #1
9 41702

misdst23 wrote:
Hi,

I know I can call a static java method within javascript by using the
<% ... %tags. But how can pass a javascript variable ?
Since you are mentioning java, I'm assuming you are creating JSP's.
function thefunction()
{

var = javascriptvaria ble ;
'var' is a keyword in javascript. Proper usage will be like the
following:

var variable_name = value;
>
<% testClass.set(v ar) ; %;

}
To do what you want, you can do something like the following:

function myFunc()
{
<%
System.out.prin tln("var variable_name = " + value);
%>
}

Your value will have to be surrounded by quotes depending on whether
it's a string value or not.

Aug 30 '06 #2

You're missing the point. I can't use a constant. I need to pass a
variable into Java.
web.dev wrote:
misdst23 wrote:
Hi,

I know I can call a static java method within javascript by using the
<% ... %tags. But how can pass a javascript variable ?

Since you are mentioning java, I'm assuming you are creating JSP's.
function thefunction()
{

var = javascriptvaria ble ;

'var' is a keyword in javascript. Proper usage will be like the
following:

var variable_name = value;

<% testClass.set(v ar) ; %;

}

To do what you want, you can do something like the following:

function myFunc()
{
<%
System.out.prin tln("var variable_name = " + value);
%>
}

Your value will have to be surrounded by quotes depending on whether
it's a string value or not.
Aug 30 '06 #3

misdst23 wrote:
You're missing the point. I can't use a constant. I need to pass a
variable into Java.
I misunderstood your question. It seemed like you were asking how to
pass a java variable to javascript. For vice versa, it is not possible
through conventional methods.

Javascript is run on the client-side. Your servlet, i.e. compiled JSP
is run on server-side. The only solution I can think of right now is
for you to use XMLHttpRequest to send the data and use something like
request.getPara meter() in your JSP.

Aug 31 '06 #4

I've come accross your point about javascript being on the client and
java on the server. BUT, the client side javascript function IS able to
pass a constant as a parameter to the server side java. It seems
logical to me that javascript should have a means to pass a variable.
Obviously, there is some sort of TCP connection going on in the back
end that allows the constant to be sent to the server. But since the
functionality is there maybe javascript should be standardized to allow
some way to pass a variable.
Thanks, I think i'll have to look into XMLHttpRequest.

Also, how can I use a image preload get to transmit a string to the
server, i've heard this is possible.

Thanks,

web.dev wrote:
misdst23 wrote:
You're missing the point. I can't use a constant. I need to pass a
variable into Java.

I misunderstood your question. It seemed like you were asking how to
pass a java variable to javascript. For vice versa, it is not possible
through conventional methods.

Javascript is run on the client-side. Your servlet, i.e. compiled JSP
is run on server-side. The only solution I can think of right now is
for you to use XMLHttpRequest to send the data and use something like
request.getPara meter() in your JSP.
Aug 31 '06 #5
Hi,

misdst23 wrote:
I've come accross your point about javascript being on the client and
java on the server. BUT, the client side javascript function IS able to
pass a constant as a parameter to the server side java.
No, it's not. In your quoted example here under, the "constant" is a
Java string. The scope of everything which is executed between <% ... %>
is the server, and it's Java.

<% testClass.set(" iiiiiiiiii") ; %>

"iiiiiiiiii i" is a Java string.

<snip>

HTH,
Laurent
--
Laurent Bugnion, GalaSoft
Software engineering: http://www.galasoft-LB.ch
Private/Malaysia: http://mypage.bluewin.ch/lbugnion
Support children in Calcutta: http://www.calcutta-espoir.ch
Aug 31 '06 #6

misdst23 wrote:
I've come accross your point about javascript being on the client and
java on the server. BUT, the client side javascript function IS able to
pass a constant as a parameter to the server side java. It seems
logical to me that javascript should have a means to pass a variable.
Obviously, there is some sort of TCP connection going on in the back
end that allows the constant to be sent to the server. But since the
functionality is there maybe javascript should be standardized to allow
some way to pass a variable.
Your missing something very key here, that is javascript cannot access
java.
What is can access are the RESULTS of that java method. You see by the
time javascript is running, the JSP has already rendered itself to HTML
output and is done.
>

Thanks, I think i'll have to look into XMLHttpRequest.
Using this you can pass a javascript variable to serverside process. If
this results in changes on the page, you'll have to either reload the
page or execute the changes yourself in javascript.
>
Also, how can I use a image preload get to transmit a string to the
server, i've heard this is possible.
By using a server side process (like a servlet) to provide the image
data, and appending a query string to the img src parameter. The server
side process will receive the request (headers, parameters and all) and
can process it before transmitting image data back (or it may not
actually send anything back...)

HTH.
>
Thanks,
Aug 31 '06 #7
"misdst23" <mi*********@ya hoo.comwrote:
>
You're missing the point. I can't use a constant. I need to pass a
variable into Java.
If you're writing a *.jsp page, then the Java code will execute on the
server. The result will be HTML which will include your Javascript
functions. That will be sent to the client, and the Javascript will
execute there.

So, by the time the Javascript is running, the Java code has been run
and is no longer there.

--
Tim Slattery
Sl********@bls. gov
Aug 31 '06 #8

ok. So you're saying that the java within the javascript is actually
executed BEFORE the javascript executes ?
By using a server side process (like a servlet) to provide the image
data, and appending a query string to the img src parameter. The server
side process will receive the request (headers, parameters and all) and
can process it before transmitting image data back (or it may not
actually send anything back...)
So I have to have a seperate servlet or something that handles the
request on the server ? It can't be part of the same jsp.

Do you have any example code on this ?
Tom Cole wrote:
misdst23 wrote:
I've come accross your point about javascript being on the client and
java on the server. BUT, the client side javascript function IS able to
pass a constant as a parameter to the server side java. It seems
logical to me that javascript should have a means to pass a variable.
Obviously, there is some sort of TCP connection going on in the back
end that allows the constant to be sent to the server. But since the
functionality is there maybe javascript should be standardized to allow
some way to pass a variable.

Your missing something very key here, that is javascript cannot access
java.
What is can access are the RESULTS of that java method. You see by the
time javascript is running, the JSP has already rendered itself to HTML
output and is done.


Thanks, I think i'll have to look into XMLHttpRequest.

Using this you can pass a javascript variable to serverside process. If
this results in changes on the page, you'll have to either reload the
page or execute the changes yourself in javascript.

Also, how can I use a image preload get to transmit a string to the
server, i've heard this is possible.


HTH.

Thanks,
Aug 31 '06 #9

misdst23 wrote:
ok. So you're saying that the java within the javascript is actually
executed BEFORE the javascript executes ?
Yes. The javascript only sees the output resulting from the java
method.
>
By using a server side process (like a servlet) to provide the image
data, and appending a query string to the img src parameter. The server
side process will receive the request (headers, parameters and all) and
can process it before transmitting image data back (or it may not
actually send anything back...)

So I have to have a seperate servlet or something that handles the
request on the server ? It can't be part of the same jsp.
You will need something Java on the server side that can get your value
to your already executing javascript. I would recommend not using the
image loading idea, but rather use an XmHttpRequest to send a response
to and read the response from a servlet. Then use javascript to update
the page.
>
Do you have any example code on this ?
There are many examples/tutorials on using XmlHttpRequest.
>

Tom Cole wrote:
misdst23 wrote:
I've come accross your point about javascript being on the client and
java on the server. BUT, the client side javascript function IS able to
pass a constant as a parameter to the server side java. It seems
logical to me that javascript should have a means to pass a variable.
Obviously, there is some sort of TCP connection going on in the back
end that allows the constant to be sent to the server. But since the
functionality is there maybe javascript should be standardized to allow
some way to pass a variable.
Your missing something very key here, that is javascript cannot access
java.
What is can access are the RESULTS of that java method. You see by the
time javascript is running, the JSP has already rendered itself to HTML
output and is done.
>
>
Thanks, I think i'll have to look into XMLHttpRequest.
Using this you can pass a javascript variable to serverside process. If
this results in changes on the page, you'll have to either reload the
page or execute the changes yourself in javascript.
>
Also, how can I use a image preload get to transmit a string to the
server, i've heard this is possible.

HTH.
>
Thanks,
Aug 31 '06 #10

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

Similar topics

3
5165
by: StealthMonkey | last post by:
Let me prefix this by saying that I know next to nothing about Java (so please try to keep explainations simple). I use PHP for my server-side web programming. Here is my dilemma: I need a JavaScript function to be called with a dynamic parameter, an ID# known by the server. The way I would go about doing this in PHP would be extremely...
2
6896
by: Eyal | last post by:
Hey, I would appriciate if anyone can help on this one: I have a java object/inteface having a method with a boolean parameter. As I'm trying to call this method from a javascript it fails on a type mismatch. It is positively because of the boolean(java primitive)parameter. It goes fine if I change this parameter to int or String. This...
3
2654
by: Rajesh | last post by:
Hi, I am using iplanet webserver 4.1. I want to call a java class from ssjs file. But I am not getting the result. I have created a java class file and put it in the folder <Server>\Netscape\Server4\bin\https\jar folder. But I am not sure whether it is the right location to put the class file. Also I would like to know how to put the class...
18
12643
by: Simula | last post by:
I am developing an HTML javascript application and I want to preserve state in a way that can be book-marked. I chose HTML anchors as a means of preserving state. When the application changes state, the HTML page URL would change from default.html to default.html#stateA. example: http://pearstudios.com/javascript/locationHashAndFlash.html ...
4
6542
by: Anita C | last post by:
Hi, Can one call a c# function from within a javascript function ? I have a c# function GetLanguageItem(title), how can I call the above function from a javascript function in an .aspx page. Thanks
4
6304
by: Martin Feuersteiner | last post by:
Dear Group I'm using VB to write an aspnet application. I would like to call a javascript function from within a VB Sub or VB Function, is it possible? My code is something like this: VB Code: Public Sub VBProcedure() .. ..
1
6719
by: Lakshmi | last post by:
Hi All, I am having performance issues with the .NET client calling the Java Webservice running on axis. Have detailed the problem below. Please help. I wrote a webservice in Java. Lets name this WebService1. (using Apache Axis 1.1) Scenario 1: -----------
4
3568
by: raghuvendra | last post by:
Hi I have a jsp page with 4 columns: namely Category name , Category order, Input field and a submit button. All these are aligned in a row. And Each Category Name has its corresponding Category order, Input field and a submit button. The Category name is being fetched from the oracle db along with the corresponding Category order. In...
2
1897
by: humberto.bortolossi | last post by:
Greetings! I'm trying to control Java Applets using JavaScript. However, the standard recipes don't work under XHTML (they work well within HTML). See, for instance, the code http://www.professores.uff.br/hjbortol/j2j/java-javascript-interaction-test-01.xhtml produces the following error message under Firefox 3.0:
0
7452
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
0
7643
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. ...
0
7798
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
1
7405
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
0
7738
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
0
5956
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
0
3441
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in...
0
3436
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
1862
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 we have to send another system

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.