aspose file tools*
The moose likes HTML, CSS and JavaScript and the fly likes Auto Refresh Table in JSP Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of EJB 3 in Action this week in the EJB and other Java EE Technologies forum!
JavaRanch » Java Forums » Engineering » HTML, CSS and JavaScript
Bookmark "Auto Refresh Table in JSP" Watch "Auto Refresh Table in JSP" New topic
Author

Auto Refresh Table in JSP

Dimitri Supinfo
Greenhorn

Joined: Jun 14, 2012
Posts: 3
Hello everyone,
i'm quite new to JSP/Servlet architecture.
I would like some help with the following problem, i'm trying to dynamically refresh the content of the following table without refreshing my whole page.



The table is filled by the following Servlet:



What is the best way to achieve my goal.

Thanks in advance.
J. Kevin Robbins
Ranch Hand

Joined: Dec 16, 2010
Posts: 632
    
    7

Use an AJAX call inside a timer loop. If you want to avoid reloading the entire page, AJAX is your only option.


"There is no reason for any individual to have a computer in his home" ~ Ken Olson, Co-founder of DEC, 1977
Palak Mathur
Ranch Hand

Joined: Jan 29, 2007
Posts: 313

You may like to use Ajax. But I think Bear would be the best person to answer.


Palak Mathur | My Blog | TechJaunt | What is JavaRanch? | List of All FAQs
Dimitri Supinfo
Greenhorn

Joined: Jun 14, 2012
Posts: 3
Thank you for your answers,

I don't know how to use AJAX, i could use so help here, would you please give me examples or tutorials?

I've already googled it and didn't find precise examples of what i need.
Santiago Tovar
Greenhorn

Joined: Jun 13, 2012
Posts: 11

It's not easy to find exactly what you need, but there are a lot of examples that you can use to understand how it works and do your own code. we can help you with the errors you get in that process.
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 60050
    
  65

Yes, you'll need to use Ajax.

Fire off an Ajax request that returns the HTML fragment (not a full page) that contains the new table markup. Replace the old table element in the DOM with the new fragment.

Do yourself a favor:
  • Get an Ajax tutorial and read about how Ajax works and what it is.
  • Then use jQuery to do your Ajax call, where it will take one line of code to accomplish the above, rather than the screen-full of code required to do it in raw JavaScript.

  • As a hint, after you learn the basics of Ajax and jQuery, the code will look something like this:


    [Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
    Dimitri Supinfo
    Greenhorn

    Joined: Jun 14, 2012
    Posts: 3
    Thanks Bear,

    I read tutorials about Ajax and JQuery as you said ! ;)

    I wrote something like that and it matches my needs.

    Tej Ernesto
    Greenhorn

    Joined: Jun 17, 2012
    Posts: 17

    we have to set the Refresh header of the response..

    5 indicates that the page refreshes automatically for 5 seconds

    response.setHeader("Refresh","5");
    Bear Bibeault
    Author and ninkuma
    Marshal

    Joined: Jan 10, 2002
    Posts: 60050
        
      65

    Tej Ernesto wrote:we have to set the Refresh header of the response..

    That will cause the entire page to refresh which is exactly what the question is not about.
     
    I agree. Here's the link: http://aspose.com/file-tools
     
    subject: Auto Refresh Table in JSP
     
    Similar Threads
    Copy and past link problem
    method showing different returns when declared on JSP or Servlet
    How to delete an element from a list?
    JSP column name hyperlink help
    pagination exception in spring