验证码生成后传输到前台展示

验证码生成后传输到前台显示
验证码目前有两种方式显示:
1、用图片流的形式输出到页面,即ImageIO.write(bufferimage,'',outputstream);
2、生成图片后在页面给一个地址去访问图片;

针对第一种:目前action类中由于继承系统原有的action,原有的action已经调用了getwriter方法,所以在我的action里面是无法调用getoutputstream的,所以第一种不行。

针对第二种:我点击页面的“看不清”后,验证码有重新生成但是在页面显示的还是原来的验证码。

请问,如果是第一种,还有没有其他输出的方法不跟getwriter冲突的?
第二种的话,如何能让重新生成验证码后,在页面也更新呢?(异步)
验证码 图片 继承

------解决方案--------------------
不要使用write 


// 在内存中创建图象


BufferedImage image = new BufferedImage(width, height,
BufferedImage.TYPE_INT_RGB);

// 获取图形上下文
Graphics g = image.getGraphics();

// 生成随机类
Random random = new Random();



// 取随机产生的认证码(4位数字)
String sRand = "";
for (int i = 0; i < 4; i++) {
String rand = String.valueOf(random.nextInt(10));
sRand += rand;
// 将认证码显示到图象中
g.setColor(new Color(20 + random.nextInt(110), 20 + random
.nextInt(110), 20 + random.nextInt(110)));
// 调用函数出来的颜色相同,可能是因为种子太接近,所以只能直接生成
g.drawString(rand, 13 * i + 6, 16);
}

// 将认证码存入SESSION
ActionContext.getContext().getSession().put("check_code",sRand);
               System.out.println("验证码:"+sRand);
// 图象生效
                   //清除缓存
g.dispose();
ByteArrayOutputStream output = new ByteArrayOutputStream();
ImageOutputStream imageOut = null;
try {
imageOut = ImageIO.createImageOutputStream(output);
ImageIO.write(image, "JPEG", imageOut);
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} finally {

try {
imageOut.close();
} catch (IOException e) {
// TODO Auto-generated catch block