后端数据通过request发送到前端JSP页面上,为什么没有数据呢

xiaoxiao2021-02-28  7

public void listTingcheweiScalar(){      Session session = factory.openSession();      Transaction tx = null;      try{      //开启事务         tx = session.beginTransaction();         //进行查询         String sql = "SELECT sum(bb) FROM Tingchewei where aa = :tingchewei_aa";         SQLQuery query = session.createSQLQuery(sql);         String sql2 = "SELECT name FROM TeamA";         SQLQuery query2 = session.createSQLQuery(sql2);         query2.setResultTransformer(Criteria.ROOT_ENTITY);         //结果存放到list         List results = query2.list();         System.out.println(results);         String[] str=new String[results.size()];         int i=0;         for(Object obj:results){          str[i++]=obj.toString();         }         List<Object> list = new ArrayList();        for(int j=0;j<str.length;j++){         query.setParameter("tingchewei_aa",str[j]);         Object count = query.uniqueResult();         System.out.println(str[j]);         list.add(count);          }        HttpServletRequest request =ServletActionContext.getRequest();        request.setAttribute("list",list);        System.out.println(list);             tx.commit();      }catch (HibernateException e) {         if (tx!=null) tx.rollback();         e.printStackTrace();       }finally {         session.close();       }

  }list里面的数据可以打印出来,

<c:forEach items="${list}" var="item"> <td> ${item} </td>

</c:forEach>

前端jsp用foreach遍历获取,为什么前端不显示数据呢

转载请注明原文地址: https://www.6miu.com/read-2400378.html

最新回复(0)