日期:2014-05-17  浏览次数:20670 次

用struts2写了一个action,在浏览器直接访问action 的地址,发现第一次访问execute方法被执行一个,第二次execute方法被执行3次!!!
第三次访问,execute方法被执行2次,以后在访问还是execute方法会被执行两次。下面是action的代码:
Java code
public class MyCaptcha extends ActionSupport implements SessionAware {

    @SuppressWarnings("rawtypes")
    private Map session;

    @SuppressWarnings("rawtypes")
    public void setSession(Map session) {
        this.session = session;

    }

    @Override
    public String execute() throws Exception {
        System.out.println("action被执行————————————————————————————————");
        HttpServletResponse response = ServletActionContext.getResponse();
        response.setContentType("image/png");
        response.setHeader("Pragma", "No-cache");
        response.setHeader("Cache-Control", "no-cache");
        response.setDateHeader("Expires", 0);
        ServletOutputStream outputStream = response.getOutputStream();
        Captcha captcha = new Captcha();
        captcha.generateImage(this.session, outputStream);
        outputStream.close();
        return NONE;
    }

}


等高手解答!!

------解决方案--------------------
不要用session