当我删除记录时记录了删除count条记录 然后把count传递到显示的action show.action页面 show.action页面是跳转到jsp页面的 我在jsp页面判断count 如果count大于0 我就打印出count信息提示用户删除了count条记录 但是当我执行一次完成后刷新jsp页面 count值仍然存在 所以判断里面的打印又执行了一次 请问 该如何吧count值清0呢?
以下是相关代码
1.action中的代码 
public class NumberAction extends ActionSupport {
.....省略了不相关的变量

private int count = 0; public String show() {
System.out.println("------count="+count+"-----------");
HttpServletRequest request = ServletActionContext.getRequest();

String sql = "select count(*) from NbrT where nbrType =" + nbr_type;

nbrtService = new NbrTServiceImpl();

int totalRows = nbrtService.getNbrRows(sql);

HttpSession session = request.getSession();
pager = PagerHelper.getPager(currentPage, pageMethod, session,
totalRows);


sql = " from NbrT where nbrType=" + nbr_type + " order by nbrUsed , nbrId desc";

nbrList = nbrtService.getNbrAllList(sql, pager.getPageSize(), pager
.getStartRow());
return SUCCESS;

} public String deleteList() {
System.out.println("====================");
int count = 0;
HttpServletRequest request = ServletActionContext.getRequest();
try {
if (checkbox != null) {
nbrtService = new NbrTServiceImpl();
for (int i = 0; i < checkbox.length; i++) {

nbrt = nbrtService.getNbrT(Integer.parseInt(checkbox[i]));
if(nbrt.getNbrUsed()==0){
if (nbrtService.deleteNbr(nbrt)) {
count++;
}
} }
if (count > 0) {
return SUCCESS;
}
}  } catch (Exception e) {
e.printStackTrace();
return ERROR;
}
return ERROR;
} public int getCount() {
System.out.println("here get  count! count="+count);
return count;
} public void setCount(int count) {
this.count = count;
}}2.struts.xml
<action name="NumberAction"
class="com.web.action.number.NumberAction" method="show">
<result>number/nbrinfo.jsp</result>
</action>
<action name="DeleteNbrList"
class="com.web.action.number.NumberAction" method="deleteList">
<result name="success" type="redirect">
/NumberAction.action?nbr_type=${nbr_type}&amp;currentPage=session&amp;count=${count}
</result>
<result name="error" type="redirect">
/NumberAction.action?nbr_type=${nbr_type}&amp;currentPage=session&amp;errorMessage=delerror
</result>
</action>3.jsp页面<s:if test='%{count>0}'>
    <script>
alert("成功删除"+${count}+"条记录!");
    </script>
</s:if>

解决方案 »

  1.   

    上面有个地方写错了 public String deleteList() { 
    System.out.println("===================="); 
    int count = 0; 
    这个地方不是int count = 0 而是直接 count = 0 调用的成员变量count
      

  2.   

    你用的这种方式,刷新后肯定count还在啊
    /NumberAction.action?nbr_type=${nbr_type}&amp;currentPage=session&amp;count=${count} 
    你刷的是这个url地址,所以他还在
      

  3.   

    问题解决了 ~<s:if test='%{count>0}'> 
        <script> 
    alert("成功删除"+${count}+"条记录!"); 
    window.location="NumberAction.action?nbr_type=${nbr_type}&currentPage=session&count=0" ; //此处把count置为0一下 
        </script> 
    </s:if> 
    不知道有没有更好的解决办法了……