ServletOutputStream out = response.getOutputStream();
try {
Robot r = new Robot();
Dimension d = Toolkit.getDefaultToolkit().getScreenSize();
Rectangle re = new Rectangle(d);
Screen s = new Screen(r, re);
ImageIO.setUseCache(false);
ImageIO.write(s.getScreenPictureBuffer(), "jpeg", out);
} catch (Exception e) {
//e.printStackTrace();
}finally{
out.close();
}