This discussion is archived
10 Replies Latest reply: Feb 21, 2013 6:35 AM by maheshguruswamy RSS

automatically updating a web page?

Murray9654 Newbie
Currently Being Moderated
Hi i have a web application. Three clients john,bob and alice are viewing the web page of that application. Now john posted a message to bob using the web app.The web app stores the message in the database. Now as soon as it is saved in the database, immediately after john posted a message, The message has to appear on the bob's page that is currently being viewed without bob refreshing the page. Is this possible in java/j2ee?
  • 1. Re: automatically updating a web page?
    761757 Newbie
    Currently Being Moderated
    One of the basic ways is to use Timer (window.setInterval) , poll the server using AJAX mechanism and refresh the data from the server (which polls the DB for the change in time stamp since you last polled ) . It would basically be a client pull rather then a server push having some time lag for sure .

    But recently came across server push technology for HTML5 , may be worth looking for you

    http://today.java.net/article/2010/03/31/html5-server-push-technologies-part-1#sse

    Edited by: EJP on 18/02/2013 14:32
  • 2. Re: automatically updating a web page?
    Kayaman Guru
    Currently Being Moderated
    Muralidhar wrote:
    Is this possible in java/j2ee?
    You're asking the same exact question in several different threads, slightly differently worded.
    We already told you that it's possible and there are several ways to do it.

    Are you going to ask the same question over and over, until someone writes the code for you? Or will you actually make an effort yourself?
  • 3. Re: automatically updating a web page?
    Murray9654 Newbie
    Currently Being Moderated
    You're asking the same exact question in several different threads, slightly differently worded.
    We already told you that it's possible and there are several ways to do it.
    sorry if my question is not self explanatory. I have not asked on any other thread about this.

    My previous question was how to get the posted comment on to his page who posted it. (on face book comments). I understood how that can be done. I am clear with that. Now my question is not about getting the message on to his page who posted it.

    It is about somebody posted the message and it has to display on some one else page. I made clear in my post that the page should not be refreshed, I don't want to poll as well. no ajax nothing. when discussing about "face book comments" on the other thread one person just suggested me to look at "websockets" for something like this. I just want to ensure that there is no way or there is way in java to meet my requirement without using any third party technologies and also "websockets" is being standardized now and only supported by recent versions.

    If you have seen me asking the same question on multiple threads can you refer the threads that i have asked this question so that i wont ask or wait for some one to reply if it is already answered.

    as you said
    Are you going to ask the same question over and over, until someone writes the code for you?
    I don't have any intentions of this sort and i am not here to waste your and my time. I know that both are (your and my time)precious and I respect everybody who keep effort in answering the questions here.
  • 4. Re: automatically updating a web page?
    DrClap Expert
    Currently Being Moderated
    I think you might be wasting your time by starting with unrealistic requirements. No polling? No AJAX? Why not?
  • 5. Re: automatically updating a web page?
    Murray9654 Newbie
    Currently Being Moderated
    DrClap wrote:
    I think you might be wasting your time by starting with unrealistic requirements. No polling? No AJAX? Why not?
    see if i use Ajax i have to go for polling. with polling we might be wasting the resources. most of the time there might not be any updates. And my requirement is simple and common. i am just asking when some one posted a message is it possible to display the message to the person whom it is intended without client making requests (polling) in any kind.

    I have seen this happening in gmail. so trying to understand how this can be done.
  • 6. Re: automatically updating a web page?
    r035198x Pro
    Currently Being Moderated
    Depends on what technologies you already have or where you are going to deploy to. pub/sub pattern could work with some appservers (weblogic) supporting an http pub/sub server. Some appservers already have reasonably stable implementations of websockets. It's unlikely that anyone is going to suggest the best approach for you here. You need to spend time researching the documentation of your current products to find out what is applicable for your application needs.
  • 7. Re: automatically updating a web page?
    Murray9654 Newbie
    Currently Being Moderated
    Is supporting websockets part of the j2ee server spec?
  • 8. Re: automatically updating a web page?
    r035198x Pro
    Currently Being Moderated
    JSR 356 is targeted at EE7 http://jcp.org/en/jsr/detail?id=356
  • 9. Re: automatically updating a web page?
    Murray9654 Newbie
    Currently Being Moderated
    Done some homework. I think websockets will solve my problem. jsr for websockets is still active so i think it still have to be finalized. Anyways thank you all.
  • 10. Re: automatically updating a web page?
    maheshguruswamy Journeyer
    Currently Being Moderated
    Muralidhar wrote:
    Done some homework. I think websockets will solve my problem. jsr for websockets is still active so i think it still have to be finalized. Anyways thank you all.
    If the updates are not that frequent, AJAX polling will probably be the better option to go with. AJAX is after all just javascript. If you need frequent, low latency updates (think gaming sites), you would need websockets. Also websockets are an evolving technology, so be aware of your users client side setup before heading down the path of websockets.

Legend

  • Correct Answers - 10 points
  • Helpful Answers - 5 points