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

Java Question - Calling JavaScript

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 simple:

<script>
foo(<?PHP echo ID; ?>);
</script>

PHP would then pre-process the PHP code and print out the content of
the variable 'ID'. When it would come time for the browser to
interpret the JavaScript it would read (for example):

<script>
foo(7);
</script>

The value '7' would then be passed into the foo() function, everything
works perfectly. The problem is that I need some way to do with with
Java. The company I work for is working with another company that uses
Java as their server-side language. I gave them this information, and
they replied saying that because they use Java, there is no way to do
this. Is that true? Is Java a preprocessor? If not, is there a work
around? Basically what it comes down to is: How can I have a
JavaScript function called with a parameter from Java?

Please help! Thanks!
Jul 17 '05 #1
3 5152
On Tue, 13 Jan 2004 09:34:47 -0800, StealthMonkey wrote:
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 simple:

<script>
foo(<?PHP echo ID; ?>);
</script>

PHP would then pre-process the PHP code and print out the content of the
variable 'ID'. When it would come time for the browser to interpret the
JavaScript it would read (for example):

<script>
foo(7);
</script>

The value '7' would then be passed into the foo() function, everything
works perfectly. The problem is that I need some way to do with with
Java. The company I work for is working with another company that uses
Java as their server-side language. I gave them this information, and
they replied saying that because they use Java, there is no way to do
this. Is that true? Is Java a preprocessor? If not, is there a work
around? Basically what it comes down to is: How can I have a JavaScript
function called with a parameter from Java?

Please help! Thanks!


You could try Mozillas Rhino (http://www.mozilla.org/rhino). You can
certainly execute JavaScript from Java using that.
Jul 17 '05 #2
It is very easy to do thish through Java. If you would use JSP the syntax
would be very similar to PHP (in fact, JSP is at all very similar to PHP).
For anything but simple thingies I would advise to use actual servlets
instead of JSP, but in this case that might be to much.

Silvio Bierman
Jul 17 '05 #3
st**************@hotmail.com (StealthMonkey) wrote in message news:<1b**************************@posting.google. com>...
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 simple:

<script>
foo(<?PHP echo ID; ?>);
</script>

PHP would then pre-process the PHP code and print out the content of
the variable 'ID'. When it would come time for the browser to
interpret the JavaScript it would read (for example):

<script>
foo(7);
</script>

The value '7' would then be passed into the foo() function, everything
works perfectly. The problem is that I need some way to do with with
Java. The company I work for is working with another company that uses
Java as their server-side language. I gave them this information, and
they replied saying that because they use Java, there is no way to do
this. Is that true? Is Java a preprocessor? If not, is there a work
around? Basically what it comes down to is: How can I have a
JavaScript function called with a parameter from Java?

Please help! Thanks!

So what is the question?

You definitely don't seem confused about serverside/clientside which
is a good thing. Are you using Java on the server side? If so, then
I'll assume you are using either servlets or JSP (Java Server Pages)
JSP is really just a different notatation for a java servlet. Both
are compiled into a .class files and executed by a 'container'
whenever an incoming request is received.

The Javascript doesn't care how the page was generated. Whether the
parameter was written into the page using PHP, JSP, servlets, or just
hardcoded HTML it makes no difference.

If you don't know what to use on the server side, try JSP. The syntax
is similar to PHP and you'll pick it up quickly.

Start by looking at or playing with Tomcat to get a feel for it.
http://jakarta.apache.org/tomcat/

---
Jared Dykstra
http://www.bork.org/~jared
Jul 17 '05 #4

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

Similar topics

5
by: Oleg Konovalov | last post by:
Hi, I am writing a Java application which among many other things has to call some MS Office internal methods, which only seems to be possible from either VBA or C#. Can anybody suggest a...
7
by: Klaus Friese | last post by:
Hi, i'm currently working on a plugin for Adobe InDesign and i have some problems with that. I'm not really a c++ guru, maybe somebody here has an idea how to solve this. The plugin is...
0
by: Oleg Konovalov | last post by:
Hi I am writing a Java application which among many other thing has to call some MS Office internal methods, which only seems to be possible from either VBA or C# Can anybody suggest a way...
5
by: Krishna | last post by:
Hi all, Can i call my javascript functions from the web controls.Any appropriate site which will be tell more on this will be helpfull. Regards.., Krishna
4
by: Oleg Konovalov | last post by:
Hi I am writing a Java application which among many other thing has to call some MS Office internal methods, which only seems to be possible from either VBA or C# Can anybody suggest a way...
9
by: J de Boyne Pollard | last post by:
TWJava and JavaScript are two different animals. ;-) DHLOK Tom. DHL> DHLDefine the two. DHL> DHLTo me Java is the software that interprets and executes DHLJavaScripts and Java Applets. ...
1
by: keith_rhodes | last post by:
Hi, all. I know that there is a way of using JavaScript to call a Java method, and for the JavaScript to collect some sort of response from the Java, as I had a page working a few years ago that...
8
by: wpelgrum | last post by:
When I open a webpage with javascript my browser (both IE6 and FF2.0.0.3) freezes anywhere from seconds to more than a minute. During that period, the browser is frozen and windows (XP-SP2) is very...
1
by: basm101 | last post by:
Hello, Firstly, apologies if this should be in the javascript forum - I wasnt sure which was most appropriate to post this question in... I am not sure if my problem is caused by the way I am...
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: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
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?
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.