• Post Reply Bookmark Topic Watch Topic
  • New Topic

Refresh a Servlet page  RSS feed

 
R Sugan
Ranch Hand
Posts: 48
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi ,

I need to refresh my Servlet page.
Following is my code..



How to refresh the page?Please give me any sample code.It is very helpful to continue this process.



Thanks
 
Ankit Garg
Sheriff
Posts: 9610
37
Android Google Web Toolkit Hibernate IntelliJ IDE Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What do you mean that you need to refresh your servlet page?? So you want the page on the client end to get refreshed automatically after a fixed period of time?? If yes, then take a look here...
 
Ulf Dittmer
Rancher
Posts: 42972
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
This is done by the HTTP "Refresh" header. You can either set that in the response object:

response.setHeader("Refresh", "5; URL=http://host/path").

or embed it in the HTML page:

<META HTTP-EQUIV="Refresh" CONTENT="5; URL=http://host/path">

Note that this depends on the client honoring this header (which it will if it's a browser, but your code looks like it might be some other kind of client).
 
R Sugan
Ranch Hand
Posts: 48
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

Thanks for your reply.Actually i am running my Servlet program when apache-tomcat start function.I modified my web.xml and include<load-on-start up>.So i can't able to use this function

response.setHeader("Refresh", "5");


Please give me any other solution.


Thanks
 
Ulf Dittmer
Rancher
Posts: 42972
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Whatever you're doing in the init method of a load-on-startup servlet is not associated to any request or response. It's done once, and then never again. So what, exactly, do you mean by "refresh"?
 
R Sugan
Ranch Hand
Posts: 48
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Hi,

When i start tomcat continuously running my servlet program.



Thanks.
 
Ulf Dittmer
Rancher
Posts: 42972
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Servlet are used for request/response situations. If you want to run code at regular intervals, check out the java.util.Timer and TimerTask classes; they can be used for periodic scheduling of code execution. This is best set up in a ServletContextListener, not in a load-on-startup servlet.
 
R Sugan
Ranch Hand
Posts: 48
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

How to set up ServletContextListener in my Servlet program.Please Give me any Sample.It is very helpful to continue this process.



Thanks.
 
Ankit Garg
Sheriff
Posts: 9610
37
Android Google Web Toolkit Hibernate IntelliJ IDE Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
A simple google search would give you loads of examples for servlet context listener. This is one of them...
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!