刷新时将值重置为零 [英] Reset a value to zero upon refresh

查看:50
本文介绍了刷新时将值重置为零的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在jsp页面中,刷新页面后,变量将保留其值.我想在每次页面刷新时将变量的值分配为零,该怎么做?

In a jsp page, a variable is retaining its value after the page is refreshed. I want to assign a value of a variable to zero every time the page refreshes, how to do that?

<%! 
    String s[] = new String[100];
    String s1[] = new String[100];
    int i=0;
 %>
<html>
    <head>
        <s:iterator value="data">
            <% 
                s1[i]=(String)request.getAttribute("build_id");
                s[i]=(String)request.getAttribute("bui_id");
                i++;
            %>
        </s:iterator>
    </head>
</html>

刷新页面后,这里的i值应重新初始化为零.

Here my i value should be re-initialized to zero, once my page refreshes.

推荐答案

<% i=0; %>将初始化servlet类的实例变量,该变量对于所有请求都是相同的(

<% i=0; %> will initialize an instance variable of your servlet class, which is the same for all requests (see this answer). Initialize your variable here instead:

    <s:iterator value="data">
        <% 
            int i = 0; // will be new for every request
            s1[i]=(String)request.getAttribute("build_id");
            s[i]=(String)request.getAttribute("bui_id");
            i++;
        %>
    </s:iterator>

这篇关于刷新时将值重置为零的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆