Newsletter

Java/Jsp-jQuery : Auto Reload Part Of Webpage In Every 5 Seconds

jQuery » on Sep 10, 2012 { 8 Comments } By Sivateja

Hi friend.., let us see how to reload/refresh any part of webpage in N number of  seconds [something like auto refresh Div content of the webpage in a specific time interval], hmm you might seen this type of usage in cricket live score websites 🙂 hope you are well aware of this, even in Facebook/Twitter too.  I will show you how to implement this using Java/jsp-jQuery API.

Files Required

  • index.jsp
  • reload-window.jsp
  • jquery-1.4.2.min.js

Directory Structure:

Output Screen:

index.jsp

<html>
<head>
<script type="text/javascript" src="JS/jquery-1.4.2.min.js"></script>
<script type="text/javascript">
     var auto = setInterval(    function ()
     {
          $('#score').load('reload-window.jsp').fadeIn("slow");
     }, 5000); // refresh every 5000 milliseconds
</script>
</head>

<body>
<center>
<font face="verdana" size="4px">
Auto Reload Part Of Webpage Every 10 Seconds In Java-Jsp-jQuery
</font><br><br>
   <img src="images/java4s.png"><br><br>
   <div id="score"></div>
</center>
</body>
</html>

reload-window.jsp

<%@page contentType="text/html" import="java.util.Date;" %>

<font face="verdana" size="2">
Current Time :<%= new java.util.Date() %>
</font>

Output Video:

​​

You Might Also Like

  ::. About the Author .::

Java4s_Author
Sivateja Kandula - Java/J2EE Full Stack Developer
Founder of Java4s - Get It Yourself, A popular Java/J2EE Programming Blog, Love Java and UI frameworks.
You can sign-up for the Email Newsletter for your daily dose of Java tutorials.

Comments

8 Responses to “Java/Jsp-jQuery : Auto Reload Part Of Webpage In Every 5 Seconds”
  1. paul says:

    this script is very well but i want to make something like that for reload some div in the page; can you help me to do that ?

  2. Java4s says:

    @paul

    Currently we are auto refreshing the div with id#score :-), out title is auto refreshing the part of webpage and i took div, to auto reload. Even you can take span or some thing contains id or class.

  3. could u please give me solution on display numbers from access database with time delay in jsp and i need to do some calculation like add/sub

  4. csrocks says:

    Hey I tried doing this but it. Isn’t getting refreshed every 1 second….and it’s showing me an error near flower braces of function()…saying dat complete the class body by putting).. What to do

  5. Mahesh says:

    Whenever we are changing a data in database then jsp will automatically show the updated data to user.i mean not to refresh or reload continuousaly when we modify data then only needs to be refreshed. How to do this…please help me

  6. Andy says:

    Thanks for the tutorial. This is what I was looking for.

  7. anand says:

    Auto Reload Part Of Webpage In Every 5 Seconds is not working in IE8 please reply.

  8. susheel says:

    hi
    i m making chat application,so i have opened the two browser i want to communicate with each-other.. whenever m sending the msg one browser to another browser it’s not going so plzzz help me how to make communication one browser to another browser (m using spring mvc) ……and how to refreshing the jsp page…

Name*
Mail*
Website



By posting your answer, you agree to our comments policy.
Most Recent Posts from Top Categories
Spring Boot Hibernate Spring
Contact | About Us | Privacy Policy | Advertise With Us

© 2010 - 2024 Java4s - Get It Yourself.
The content is copyrighted to Sivateja Kandula and may not be reproduced on other websites.