qq_23887889 2016-11-17 09:18 采纳率: 0%
浏览 1631

struts2 我在jsp页面中获取到了list集合中的对象但是就是不显示值

我用struts2在jsp中遍历了一个集合,集合中也有数据就是没法显示,如果用el表达式取对象
可以打印出来,但是取对象的属性就报错
先上代码
// action层
@Controller
public class NreportAction extends BaseAction
{
/**
* 内部审计S相关的封装
*/
@Resource
private NreportService nreportService; // 内审service
private List nreportList;
private Nreport nreport;

public NreportAction(){
    System.out.println("进来了");
}

// 内审填报页面
public String addUI(){
    System.out.println("时空裂缝");
    try {
        // System.out.println("1.先查出上一年没有完成的任务");
        // System.out.println("2.查询出纪检监察室下发状态 , 如果下发了,就显示一条记录,让下级部门填写");

        nreportList = nreportService.findNotDoPro();

        if(nreportList!=null && nreportList.size()>0){
            System.out.println("上一年未完成的项目有"+nreportList.size()+"个");
        }
    } catch (Exception e) {
        System.out.println(e.getMessage());
    }
    return "reportUI";
}

DAO层

public class NreportDaoImpl extends BaseDaoImpl implements NreportDao
{

@Override
public List<Nreport> findNotDoPro() {
    Calendar c=new GregorianCalendar();//新建日期对象 int year=c.get(Calendar.YEAR);//获取年份 int month=c.get(Calendar.MONTH);/
    // 获取当前年份
    int year=c.get(Calendar.YEAR);
    // sql语句    select proid from record where state=1 and (year like '%2015%')
    // 从【记录表】查询 出上一年没有完成的记录,然后根据记录从【内部表】查出项目的List
    List list = getSession().createSQLQuery(
            "select proid from record where state=0 and deptType = '内部审计' and (year like \'%" + String.valueOf(year-1) + "%\')").list();
    // 遍历List然后根据这个id来去查找林外一张表
    String sql = "select * from nreport where nid in(";
    for(int i=0;i<list.size();i++){
        // sql = "where id in(1,2,3)";
        // 如果当前获取的这个id不是最后一个id,那么加上‘,’
        if(list.get(i)!= list.get(list.size()-1)){
            sql+=list.get(i)+",";
        }else{
            sql+=list.get(i)+")";
        }
    }
    System.out.println(sql+"看看sql长啥样");
    // 从【内部表】查出未完成项目的List
    List<Nreport> list2= getSession().createSQLQuery(sql).list();
    return list2;
}

}

jsp

               <form  action="" method="post" enctype="multipart/form-data">

                    <table width="100%" border="0">
                        <tr class="t_tit">
                            <td width="40" align="center">序号</td>
                            <td width="80" align="center">项目名称</td>
                            <td width="80" align="center">审计类型</td>
                            <td width="40" align="center">送审金额</td>
                            <td width="40" align="center">预计审计费</td>
                            <td width="160" align="center">预计审计时间</td>  
                            <td width="140" align="center">经费来源</td>    
                            <td width="100" align="center">资金性质</td>
                            <td width="60" align="center">状态</td>   
                            <td width="60" align="center">备注</td>   
                            <td width="60" align="center">删除</td>   
                        </tr>


                    <!-- 如果有上一年的已经启动但是没有完成的计划也显示在这里 -->
                    <s:iterator value="nreportList" status="st">
                        ${nreportList[0]     }
                        <s:if test="nreportList!=null">
                        <tr <s:if test="#st.odd">bgcolor="f8f8f8"</s:if> >
                            <td align="center"><s:property value="nid"/></td>
                            <td align="center"><s:property value="proname"/></td>
                            <td align="center"><s:property value="audittype"/></td>
                            <td align="center"><s:property value="ssmoney"/></td>
                            <td align="center"><s:property value="expeauditmoney"/></td>
                            <td align="center"><s:property value="expeaudittime"/></td>
                            <td align="center"><s:property value="moneyfrom"/></td>
                            <td align="center"><s:property value="moneyfunds"/></td>
                            <td align="center"><s:property value="state"/></td>
                            <td align="center"><s:property value="memo"/></td>
                        </tr></s:if>
                        <s:else>没数据?</s:else>
                    </s:iterator>

                如果我 我jsp中写成上面这样   ${nreportList[0]     }   就会输出toString格式的对象    [Ljava.lang.Object;@20d77d7d 

                如果写成   ${nreportList[0].getNid   }就报错
                错误信息:
                十一月 17, 2016 5:09:16 下午 org.apache.catalina.core.ApplicationDispatcher invoke

严重: Servlet.service() for servlet jsp threw exception
java.lang.NumberFormatException: For input string: "getNid"
at java.lang.NumberFormatException.forInputString(NumberFormatException.java:65)
at java.lang.Integer.parseInt(Integer.java:492)
at java.lang.Integer.parseInt(Integer.java:527)
at javax.el.ArrayELResolver.coerce(ArrayELResolver.java:161)
at javax.el.ArrayELResolver.getValue(ArrayELResolver.java:45)
... ...

页面显示出来表格了,是迭代出来的就是没有数据,都是空的格子
![图片说明](https://img-ask.csdn.net/upload/201611/17/1479374227_31350.jpg)

求大神指导怎么才能迭代出来数据???
没有C币 , 下次有了一定加倍赏。。。
  • 写回答

1条回答 默认 最新

  • qq_23887889 2016-11-17 13:55
    关注

    终于知道为什么了哈哈哈哈,先给出大神解决地址 http://blog.sina.com.cn/s/blog_929b09ac0101d05j.html
    大家可以自己先去看看,原来是hibernate使用原生的查询语句返回的是object对象,而且不能直接转化成bean,所以会报
    [Ljava.lang.Object; cannot be cast to cn.itcast.sbgl.report.entity.Nreport 错误!

    评论

报告相同问题?

悬赏问题

  • ¥60 版本过低apk如何修改可以兼容新的安卓系统
  • ¥25 由IPR导致的DRIVER_POWER_STATE_FAILURE蓝屏
  • ¥50 有数据,怎么建立模型求影响全要素生产率的因素
  • ¥50 有数据,怎么用matlab求全要素生产率
  • ¥15 TI的insta-spin例程
  • ¥15 完成下列问题完成下列问题
  • ¥15 C#算法问题, 不知道怎么处理这个数据的转换
  • ¥15 YoloV5 第三方库的版本对照问题
  • ¥15 请完成下列相关问题!
  • ¥15 drone 推送镜像时候 purge: true 推送完毕后没有删除对应的镜像,手动拷贝到服务器执行结果正确在样才能让指令自动执行成功删除对应镜像,如何解决?