当前位置: 代码迷 >> Java Web开发 >> 用struts2写了一个action,在浏览器直接访问action 的地址,发现第一次访问execute方法被执行一个,第二次execute方法被执行3次!解决方法
  详细解决方案

用struts2写了一个action,在浏览器直接访问action 的地址,发现第一次访问execute方法被执行一个,第二次execute方法被执行3次!解决方法

热度:145   发布时间:2016-04-17 00:51:32.0
用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
  相关解决方案