By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
438,541 Members | 1,106 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 438,541 IT Pros & Developers. It's quick & easy.

Java Question - Calling JavaScript

P: n/a
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
Share this Question
Share on Google+
3 Replies


P: n/a
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

P: n/a
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

P: n/a
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 discussion thread is closed

Replies have been disabled for this discussion.