Hi There,

I got stuck in java servelt, where i hav to write a Ajax  for the energy
attribute of the mystatus class so tht it value gets refreshed(Not the whole
page) in every 5sec without the reloading of the whole page.Below is the
handler class which generates random number for energy attribute now i jst
hav to make it changed automatically in every 5secs . Thx in advance for any
help


public class StatusHandler implements RequestHandler {

private static final double ENERGY_PER_SECOND = 1.0 / 20;
 private String resourceFile;
 public StatusHandler(String resource) {
this.resourceFile = resource;
}
 @Override
public void handleRequest(HttpServletRequest req, HttpServletResponse res)
throws Exception {
long sessionCreated = 0L;
long baseEnergy = 40;
long additionalEnergy = 0L;
try {
sessionCreated = (Long)
req.getSession(false).getAttribute("sessionCreated");
long currentTime = System.currentTimeMillis();
long diffSince = currentTime - sessionCreated;
 long timeElapsedInSeconds  = (long) (diffSince * 1.0/1000);
additionalEnergy = (long) (timeElapsedInSeconds * ENERGY_PER_SECOND);
} catch (Exception e) {
e.printStackTrace();
additionalEnergy = 0L;
}
 long totalEnergy = baseEnergy + additionalEnergy;

byte[] content = FileUtils.getFileContent(resourceFile);
String respStr = new String(content, "UTF-8");
respStr = String.format(respStr, totalEnergy);
res.getWriter().print(respStr);
res.getWriter().flush();
}

}

Regards
Sam

-- 
You received this message because you are subscribed to the Google Groups 
"Google Web Toolkit" group.
To post to this group, send email to google-web-toolkit@googlegroups.com.
To unsubscribe from this group, send email to 
google-web-toolkit+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/google-web-toolkit?hl=en.

Reply via email to