|
Servlet that automatically refreshes |
|
|
This J2EE tip provides a way of automatically refreshing a servlet to a
specified URL. The refressing is done for every specified seconds.
For example, here current date will be reffeshed for every 3 seconds.
Generally the developer may use this method to display live scores.
/*
First Servlet
*/
import javax.servlet.*;
import javax.servlet.http.*;
import java.io.*;
import java.util.*;
public class FirstServlet extends HttpServlet {
public void doGet(HttpServletRequest request,
HttpServletResponse response)
throws ServletException , IOException {
try {
response.setContentType("text/plain");
PrintWriter out = response.getWriter();
response.sendRedirect("/Second");
} catch(Exception e) {
System.out.println(e.getMessage());
}
}
}
/*
SecondServlet
*/
import javax.servlet.*;
import javax.servlet.http.*;
import java.io.*;
import java.util.*;
public class SecondServlet extends HttpServlet {
public void doGet(HttpServletRequest request,HttpServletResponse response)
throws ServletException , IOException {
response.setContentType("text/plain");
response.setHeader("Refresh","3");
/* set the Haeder for how many seconds u want to
refresh the page
*/
PrintWriter out = response.getWriter();
Date d = new Date();
out.println(d.toString());
}
}
|
Related Tips
|
Page 1 of 0 ( 0 comments )
You can share your information about this topic using the form below!
Please do not post your questions with this form! Thanks.