Running Servlet

Discussion in 'Javascript' started by agapitolw@yahoo.es, Aug 27, 2007.

  1. Guest

    Dear Newsgroup

    Could you kindly explain how it is possible to run a servlet from
    javascript code ? For example , I have:

    <script language="JavaScript">
    function open_a_window(){
    childwin = window.open("showdata.jsp","dataname",
    "height=300,width=100");
    </script>

    that opens a jsp page called showdata. However, I would like to run a
    servlet that extracts data from database and forwards the results to
    be displayed in showdata.jsp.

    Thank you
     
    , Aug 27, 2007
    #1
    1. Advertising

  2. wrote:
    > Could you kindly explain how it is possible to run a servlet from
    > javascript code ? For example , I have:
    >
    > <script language="JavaScript">


    <script type="text/javascript">

    > function open_a_window(){
    > childwin = window.open("showdata.jsp","dataname",
    > "height=300,width=100");


    For accessibility, "resizeable,scrollbars" is mandatory.

    > </script>
    >
    > that opens a jsp page called showdata. However, I would like to run a
    > servlet that extracts data from database and forwards the results to
    > be displayed in showdata.jsp.


    JSPs are *JavaServer* Pages, and Java programming is off-topic here.

    ISTM your problem is that you have not understood the client-server
    architecture of the Web yet. What happens is:

    1. The client (here: browser) accesses foo.jsp on the server through
    HTTP(S).
    2. The Web server (e.g. Apache) has .jsp resources associated with the
    server-side Java engine. It calls Java, passing the .jsp resource.
    3. Java executes the .jsp resource, and generates a markup document
    from it (e.g. HTML).
    4. The server serves that document to the browser, which displays it.
    5. The markup document may also contain client-side J(ava)Script code,
    which the browser has associated with the client-side script engine.
    The browser passes that code to the client-side script engine.
    6. The client-side script engine executes that script code.
    7. The script code code may (but does not have to) trigger a request
    to the server (as your window.open() call does), and everything
    starts all over again.

    Now you want the client-side script engine to tell the server that it should
    run a servlet (server-side applet). But that script engine does not even
    "know" that the code it is executing was generated by the server; it merely
    executed some code that the browser passed to it.

    The only chance is that the script engine tells the browser to make a
    request to the server, that makes the server call Java, that executes Java
    code that accesses the database to generate from the retrieved data another
    resource, that is then served by the server to the browser.

    IOW: You have a Java problem, not a JavaScript problem. Post to
    comp.lang.java.databases instead.

    (That said, there is also server-side J[ava]Script, but that does not apply
    here.)


    HTH

    PointedEars
    --
    Anyone who slaps a 'this page is best viewed with Browser X' label on
    a Web page appears to be yearning for the bad old days, before the Web,
    when you had very little chance of reading a document written on another
    computer, another word processor, or another network. -- Tim Berners-Lee
     
    Thomas 'PointedEars' Lahn, Aug 27, 2007
    #2
    1. Advertising

  3. josh Guest


    > 3. Java executes the .jsp resource, and generates a markup document
    > from it (e.g. HTML).


    before generating an HTML file it makes a .java file that contains
    the .jsp page
    code (converts in a servlet) than that file is compiled to a .class
    file and then it has
    send to the client

    > run a servlet (server-side applet).


    a servlet is not a server-side applet. They are different things! an
    applet
    executes in a client host while a servlet in a server host. I think
    that is not
    correct to say server-side applet but may be should be better to say
    as described
    on the Sun site:
    >> A servlet can almost be thought of as an applet that runs on the server side--without a face.


    but they are not, technically, the same.
     
    josh, Aug 28, 2007
    #3
    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. Andy Fish
    Replies:
    4
    Views:
    2,451
    Andy Fish
    Dec 17, 2003
  2. Sean Clarke
    Replies:
    1
    Views:
    1,950
    Sudsy
    Jan 7, 2004
  3. circuit_breaker
    Replies:
    2
    Views:
    2,092
    Jack Jia
    Apr 4, 2004
  4. chamikara
    Replies:
    1
    Views:
    49,975
  5. Replies:
    4
    Views:
    851
Loading...

Share This Page