Call Java Method from javascript

Discussion in 'Java' started by BigZero, May 8, 2008.

  1. BigZero

    BigZero Guest

    Hello,

    can i call Java method that is java code from javascript,here what i m
    looking for i have class called DB in this class all the DB related
    things ,like DB connection DB insert,DB read etc Methods are defined.

    "All i m looking for just call the DB method from javascript that Read
    data from DB"
    is there any way that i can do this work.("not with Applet.")


    Thanks
    VM
    BigZero, May 8, 2008
    #1
    1. Advertising

  2. BigZero

    Dave Miller Guest

    Sabine Dinis Blochberger wrote:
    > BigZero wrote:
    >
    >> Hello,
    >>
    >> can i call Java method that is java code from javascript,here what i m
    >> looking for i have class called DB in this class all the DB related
    >> things ,like DB connection DB insert,DB read etc Methods are defined.
    >>
    >> "All i m looking for just call the DB method from javascript that Read
    >> data from DB"
    >> is there any way that i can do this work.("not with Applet.")
    >>

    >
    > You can use AJAX with JSP/servlets, probably. For more on AJAX, post
    > to/research comp.lang.javascript

    JavaScript is running on the client, Java (absent an applet) is running
    on the server. If you want data to be available to the js onload use a
    jsp to get the data from the DB and print ithe data to the page with the
    js like var v = <%out.print(data_from_db);%>

    To access the data after the page is loaded, have the js pass the
    parameters to a servlet or jsp (Java), have the Java query the DB for
    the data and then reload the page as above.
    --
    Dave Miller
    Java Web Hosting at:
    http://www.cheap-jsp-hosting.com/
    Dave Miller, May 8, 2008
    #2
    1. Advertising

  3. BigZero

    Mark Space Guest

    BigZero wrote:
    > Hello,
    >
    > can i call Java method that is java code from javascript,here what i m
    > looking for i have class called DB in this class all the DB related
    > things ,like DB connection DB insert,DB read etc Methods are defined.


    Basically, no. You can't and you don't want to, it's a bad idea.

    For how to do this correctly:

    <http://www.javapassion.com/ajaxcodecamp/>

    Javapassion.com web site has an excellent introduction to AJAX and also
    an introduction to several libraries/toolkits/frameworks that you can
    use. There are step-by-step instructions for getting each framework
    running and how to use it (in a simple page) plus some good explanation
    of what goes on under the hood.
    Mark Space, May 8, 2008
    #3
  4. BigZero

    Arne Vajhøj Guest

    BigZero wrote:
    > can i call Java method that is java code from javascript,here what i m
    > looking for i have class called DB in this class all the DB related
    > things ,like DB connection DB insert,DB read etc Methods are defined.
    >
    > "All i m looking for just call the DB method from javascript that Read
    > data from DB"
    > is there any way that i can do this work.("not with Applet.")


    You can do:

    Client | Network | Server
    JavaScript--(call)--Java Applet-----(JDBC over TCP/IP)-----database

    or:

    Client | Network | Server
    JavaScript-----(HTTP)-----Server side script--(DB API)--database

    The server side script can obviously be done using Java servlet/JSP.

    Or it can be done using any other technologu (ASP.NET, PHP,
    Perl CGI etc.).

    The last technique is in most forms called AJAX in todays
    terminology.

    Arne
    Arne Vajhøj, May 9, 2008
    #4
  5. BigZero

    BigZero Guest

    Thanks for every one

    i m thinking to move to "AJAX" let c what it has in it.





    Thanks
    VM
    BigZero, May 9, 2008
    #5
  6. BigZero

    copernic777 Guest

    copernic777, May 9, 2008
    #6
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. =?ISO-8859-1?Q?Thomas_Gagn=E9?=
    Replies:
    9
    Views:
    11,192
    Jezuch
    Jul 3, 2003
  2. mcdeveloper
    Replies:
    1
    Views:
    4,167
    mcdeveloper
    Jun 13, 2006
  3. Ian
    Replies:
    2
    Views:
    330
    Ulrich Petri
    Sep 6, 2003
  4. Paka Small
    Replies:
    15
    Views:
    907
  5. Replies:
    2
    Views:
    184
    hust6
    Jun 6, 2006
Loading...

Share This Page