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

action中的list在jsp中为空,为什么?
写了一个action类自己在action类中system.out.println打印出list的size为3,我在相应的jsp转发页面中却无法遍历,
不罗嗦上代码
这是action类
Java code

package com.actions;

import java.util.List;

import javax.annotation.Resource;

import com.dao.interfaceImp.BasicUserDaoImp;
import com.xu.model.BasicUser;

public class showAllUsers {
    private BasicUserDaoImp budi;
    private List<BasicUser> bus;
    
    public BasicUserDaoImp getBudi() {
        return budi;
    }
    @Resource(name="BasicUserDaoImp")
    public void setBudi(BasicUserDaoImp budi) {
        this.budi = budi;
    }
    
    public List<BasicUser> getBus() {
        return bus;
    }
    public void setBus(List<BasicUser> bus) {
        this.bus = bus;
    }
    public String execute(){
        try{
            List<BasicUser> bus = budi.findAllBasicUser();
            return "success";
        } catch (Exception e){
            e.printStackTrace();
            return "input";
        }
    }
}



这是action相对应的转发jsp
HTML code

<%@ page language="java" import="java.util.*" pageEncoding="GB18030"%>
<%@ taglib  prefix="s" uri="/struts-tags" %>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
  <head>
    <base href="<%=basePath%>">
    
    <title>My JSP 'showAllBasicUser.jsp' starting page</title>
    
    <meta http-equiv="pragma" content="no-cache">
    <meta http-equiv="cache-control" content="no-cache">
    <meta http-equiv="expires" content="0">    
    <meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
    <meta http-equiv="description" content="This is my page">
    <!--
    <link rel="stylesheet" type="text/css" href="styles.css">
    -->

  </head>
  
  <body>
  <table>
  <s:iterator value="bus" id="bs">
      <tr>
          <td>
              <s:property value="bs.id"/>
          </td>
          <td>
              <s:property value="bs.username"/>
          </td>
          <td>
              <s:property value="bs.branchBankName"/>
          </td>
      </tr>
      </s:iterator>
  </table>
      <s:debug/>
  </body>
</html>


现在的问题是action中的bus不是空的 但是在相对应的jsp中确实空的(我通过点击s:debug查看到)value stack content中bus为null,各位高手们我什么地方错了!

------解决方案--------------------
= =。。
Java code

    public String execute(){
        try{
           bus = budi.findAllBasicUser();
            return "success";
        } catch (Exception e){
            e.printStackTrace();
            return "input";
        }
    }

------解决方案--------------------
List<BasicUser> bus = budi.findAllBasicUser();
红色部分删掉就行了。
------解决方案--------------------
+1 就是这个意思
探讨

List<BasicUser> bus = budi.findAllBasicUser();
你这里重新定义了 bus ,会把类变量 bus覆盖掉 ,所以 类变量bus还是 没有数据 ,你应该吧
List<BasicUser> bus = budi.findAllBasicUser();
改成
bus = budi.findAllBasicUser();