• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Auto Refresh Table in JSP

 
Dimitri Supinfo
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Bartender
Pie
Posts: 1801
28
Chrome Firefox Browser jQuery Linux MySQL Database Netbeans IDE
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Use an AJAX call inside a timer loop. If you want to avoid reloading the entire page, AJAX is your only option.
 
Palak Mathur
Ranch Hand
Posts: 342
IntelliJ IDE Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You may like to use Ajax. But I think Bear would be the best person to answer.
 
Dimitri Supinfo
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 11
Java Spring Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 65216
95
IntelliJ IDE Java jQuery Mac Mac OS X
  • Likes 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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:

     
    Dimitri Supinfo
    Greenhorn
    Posts: 3
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    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
    Posts: 19
    Java
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    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
    Pie
    Posts: 65216
    95
    IntelliJ IDE Java jQuery Mac Mac OS X
    • Likes 1
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    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.
     
    • Post Reply
    • Bookmark Topic Watch Topic
    • New Topic