JSP写的图片输出页面。
过程是把图片A绘到另一张模板图片B上,但更换图片A后输出的始终是最初的输出图片,只有重启tomcat后才更新,删除work目录下的文件都不行。
请问这是什么原因造成的?

解决方案 »

  1.   

    在程序最后加上System.gc(); 试试
    多刷新几次
      

  2.   

    你创建的图片例如img;
    使用完之后对其使用img. Dispose();
    这个内存管理我也不太会
      

  3.   

    哎 搞不定哦 来交流下了  你画图是不是用了applet一样的小程序啊
      

  4.   

    跟后台无关,而是由于你引用图片的URL不变,你传入一个随机数变量,如:
    out.println("<img border=1 src='getImage.jsp&RAND_ID="+System.currentTimeMillis()+"'>");
      

  5.   

    浏览器缓存问题,url后跟个当前时间参数吧
      

  6.   

    不是aplet,是Graphics,各种尝试目前只有3楼的方法(更改图片A的名称)成功过,只不是不明白为什么
      

  7.   

    源代码:import java.awt.Color;
    import java.awt.Font;
    import java.awt.Graphics2D;
    import java.awt.geom.AffineTransform;
    import java.awt.image.AffineTransformOp;
    import java.awt.image.BufferedImage;
    import java.io.File;
    import java.io.IOException;
    import java.io.OutputStream;import javax.imageio.ImageIO;
    import javax.swing.ImageIcon;public class NewIMG {
    BufferedImage template = null;
    Graphics2D g = null; public NewIMG(String templatePath) {
    try {
    this.template = ImageIO.read(new File(templatePath));
    } catch (IOException e) {
    System.out.println("模板读取失败!" + e.getMessage());
    }
    g = (Graphics2D) this.template.getGraphics();
    } public boolean drawHead(String path) {
    ImageIcon head = new ImageIcon(path);
    int w = 303, h = 406, iw = head.getIconWidth(), ih = head
    .getIconHeight();
    double n = 1.0;
    if ((w + 0.0) / h < (iw + 0) / ih)
    n = (w + 0.0) / iw;
    else
    n = (h + 0.0) / ih;
    return g.drawImage(head.getImage(), 385, 787 - (int) (ih * n + 0.5),
    (int) (iw * n + 0.5), (int) (ih * n + 0.5), null);
    } public void drawInfo(String name, String post, String date) {
    g.setColor(Color.black);
    g.setFont(new Font("宋体", Font.BOLD, 54));
    g.drawString(name, 350, 931);
    g.drawString(post, 350, 1012);
    g.drawString(date, 350, 1093); } public BufferedImage Enlarge(BufferedImage src, double multiple) {
    AffineTransformOp op = new AffineTransformOp(
    AffineTransform.getScaleInstance(multiple, multiple), null);
    return op.filter(src, null);
    } public void Out(File file, String type, double multiple) {
    try {
    ImageIO.write(Enlarge(template, multiple), type, file);
    } catch (IOException e) {
    System.out.println("导出图片失败!" + e.getMessage());
    }
    } public void Out(OutputStream output, String type, double multiple) {
    try {
    ImageIO.write(Enlarge(template, multiple), type, output);
    } catch (Exception e) {
    System.out.println("导出图片失败!" + e.getMessage());
    }
    } public void flush() {
    g.dispose();
    g.dispose();
    template.flush();
    System.gc();
    }
    }