Java Question - Calling JavaScript

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • StealthMonkey

    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!
  • Tanktarta

    #2
    Re: Java Question - Calling JavaScript

    On Tue, 13 Jan 2004 09:34:47 -0800, StealthMonkey wrote:
    [color=blue]
    > 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![/color]

    You could try Mozillas Rhino (http://www.mozilla.org/rhino). You can
    certainly execute JavaScript from Java using that.

    Comment

    • Silvio Bierman

      #3
      Re: Java Question - Calling JavaScript

      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


      Comment

      • Jared Dykstra

        #4
        Re: Java Question - Calling JavaScript

        stealthmonkey10 [email protected] (StealthMonkey) wrote in message news:<1b3943f2. 0401130934.7bf9 [email protected] ogle.com>...[color=blue]
        > 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![/color]


        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.


        ---
        Jared Dykstra

        Comment

        Working...