SSH学习日记
2012-05-01 16:26
99 查看
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页面里面就是查不到,悲催
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
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页面里面就是查不到,悲催
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
相关文章推荐
- 杰奇登录后的东西都是在session里面的
- Prototype源码浅析 String部分(二)
- Apache Web让JSP“动”起来
- 深入解析Session是否必须依赖Cookie
- PHP STRING 陷阱原理说明
- PHP Session变量不能传送到下一页的解决方法
- PHP中的session永不过期的解决思路及实现方法分享
- asp.net String.IsNullOrEmpty 方法
- javascript String 对象
- 判断Session的过期时间 采用JavaScript实时显示剩余多少秒
- mysql输出数据赋给js变量报unterminated string literal错误原因
- ASP.NET Session的七点认识小结
- javascript String 的扩展方法集合
- 推荐学习php sesson的朋友必看PHP会话(Session)使用入门第1/2页
- JSP 多条SQL语句同时执行的方法
- C#中string与byte[]的转换帮助类-.NET教程,C#语言
- JSP避免Form重复提交的三种方案
- jsp遍历文件夹下的文件的代码