SSH学习日记

QueryAllAction中

public String queryAll() throws Exception{
  List<Student> studentlist=new ArrayList<Student>();
  Session session=null;
  try{
   session=HibernateUtil.getSession();
   String hql="from Student stu";
   Query q=session.createQuery(hql);
   studentlist=q.list();
   request.setAttribute("studentlist",studentlist);发火//此句忘了没写,jsp页面里面就是查不到,悲催SSH学习日记_第1张图片

   for(java.util.Iterator<Student> iterator= studentlist.iterator();iterator.hasNext();){
    Student student=(Student)iterator.next();
    System.out.println("id: "+student.getId()+" "+"姓名: "+student.getName()+" "+"性别: "+student.getSex()+" "+"地址: "+student.getAddress());
   }
  
    }catch(Exception e){
     e.printStackTrace();
    }finally{
     HibernateUtil.closeSession();
    }
  return "queryAll";
 }

queryAll.jsp

<table>
       <c:forEach items="${studentlist}" var="list">
         <tr>
            <td align="center">${list.id}</td>
            <td>${list.name}</td>
            <td>${list.sex}</td>
            <td>${list.address}</td>
            <td></td>
         </tr>
       </c:forEach>
     </table>

http://localhost:8080/Hibernate0001/queryAllAction

你可能感兴趣的:(SSH学习日记)