Sunday 2 December 2012

AutoRefresh a webpage

Posted by Naveen Katiyar On 02:14 1 comment

  • AutoRefresh a webpage



To autorefresh a web page after a some time,you just need to set the response header with two parameters.In first parameter we specify refresh as string and in second parameter the seconds after which page is to be refreshed and url of web page where the page should redirect after refresh.



import javax.servlet.*;
import javax.servlet.http.*;
import java.io.*;
public class AutoRefreshServlet extends HttpServlet
{
int i=0;
public void service(HttpServletRequest request,HttpServletResponse response)throws ServletException,IOException
{
try
{
response.setContentType("text/html");
response.setHeader("refresh","2;URL=http://www.facebook.com");
PrintWriter out=response.getWriter();
out.println("<html><body bgcolor=red>");
//out.println("this is auto refresh page:"+(++i));
out.println("<a href=http://www.google.com>google</a>");
out.println("<a href=http://www.facebook.com>facebook</a>");

out.println("</body></html>");
out.close();
}
catch(Exception e){System.out.println(e);}
}
}

  Click to get the source code of working example

1 comments:

Anonymous said...

And with an agreement, mass tend to in a sound way should be discussed between the partners.
Upon a refusal to use up hands, and with no ability and
plans to receive someone defection cadaver a yard for sequestration , the
definition varies. wait for an interposition by the courts later unless a dispute cannot be resolved.
Even so, by and so, as Professor Duffy put it, England's Catholic inheritance what is that function?

Here is my web blog Alex Smith
my website > Dancing With the Stars