JAVA -- Ajax question?

Discussion in 'Digital Media' started by Sure, Apr 12, 2008.

  1. Sure Guest

    Sure
    I currently did a small project which consumes a webservice and uses JDBC

    1. My main method calls the database using JDBC and looks for a long number where id = args[0] and closes the connections
    2. This number is given to a webservice and will return the status
    In webservice client code, I basically send a request to Webservice
    if status = 100 print success
    if status = 200 print failure
    if status>100 && status!=200 {print pending on console
    sleep 10 secs
    continue request again within loop
    }
    The control comes out from webservice client only after it has status 100 or 200 otherwise it keeps requesting again & again
    Now Instead of Using a main method I want to use a JSP page to enter the Id
    features:
    PART I
    1. A simple Jsp which takes a tarcking number (int value) and has a submit button.
    2. onSubmit the number should goto backend and check the database and will obtain another long number.
    3. The long number is given to webservice client and it pings the webservice server.
    4. Here comes the best part --- If success , print success on JSP
    If failure, print failure on JSP
    But if pending , I want it to print on Jsp pending and continue send request within loop and keep on updating the Jsp page
    until success or failure.
    I want to use Ajax to update the page every time a status is obtained at webservice client.
    PART II
    If I can do this , I wanted to add one more feature to JSP.
    When status is pending... It keeps on waiting & updating. So this would be wasting time waiting. Therefore I want to add a button on top of Page "New"
    on clicking New , a new text field , a submit button , a close button should be formed.
    Once they are formed I can enter other id and hit submit to get the status of other id. or I can click on close button and 2nd text filed,
    submit button & close button should vanish from page.
    Let us assume the otherId submission returns succes/failure immediately, then I can see success next to Second text filed and also
    the working of first should continue it should keep on updating that part until success/failure .
    If I hit New button again A new set of textfield , submit Button & close Button should be formed . ... the working of all above sets should continue.
    ie If i hit "New" button N times, N sets should be formed and if for all of them, if I hit submit all N should work simultaneously, If few have completed say 3 ,
    that 3 can remain like that and rest N-3 should keep working.

    Note: Once I get the long number from JDBC, the connections are closed. So for every new request a connection is started and closed after
    value is given back. Same is the case with webservice. when u give the long number to service, a session is opened relative to that long number.

    I need Help with Ajax, please point me to examples or code snippets.Any suggestions ??. I even thought of autocomplete in textfield which should be updated from JDBC.
    But realized opening a connection, parsing XMLHTTPRequest wont happen that fast and may be waste of time. If u think this can also be incorporated that would be great, But Part I and Part II are
    mandatory.
    My project is similar to websites that update stock values, one corner there is Yahoo stocks , 2nd corner u have google stocks.... All keep updating at same time
    every few minutes.

    Thank you. I will keep working on it and will update If I find something . Any help is appreciated.
    Sure,

Share This Page