首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > JAVA > Java Web开发 >

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

2012-01-13 
用struts2写了一个action,在浏览器直接访问action 的地址,发现第一次访问execute方法被执行一个,第二次exe

用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

热点排行