怎么用hibernate在jsp页面显示**库**

时间:2016.01.07 发布人:alrqyx4

怎么用hibernate在jsp页面显示**库**

已解决问题

谷歌alrqyx4用户在2016.01.07提交了关于“峨眉山怎么用hibernate在jsp页面显示**库**”的提问,欢迎大家涌跃发表自己的观点。目前共有1个回答,最后更新于2024-10-31T17:51:24。希望大家能够帮助她。

详细问题描述及疑问:期待您的答案,感谢你,我会记得你对我的好的 !

希望以下的回答,能够帮助你。

第1个回答

用户名:huiyanyue  

jsp页面显示**库**,后台hibernate操作方法:
在用hibernate中通过queryAllEmp()获取**库中员工信息:
publicList<Emp>queryAllEmp();//查询全部**的方法
在接口实现类EmpDa杂仍有机均提活刑oImp类中实现queryAllEmp()方法,实现类EmpDaoImp中queryAllEmp()方法的代码如下:
p行列列备艺木因才ublicList<E题井新基年刘局料末棉mp>queryAllEmp(){
List<Emp>li镇权体温本st=session.createQuery("fromEmp").list();//查询财车全部
tr.commit(刚天变衣英哥笔验山);//提交事务
returnlist;
}
页面跳转到ShowAllEmpServlet,该类是一个Servlet,用车补落来显示全部员工信息,ShowAllEmpServlet的代码如下:
packagecom.cn.service;
publicclassShowAllEmpServletextendsh**ttpServlet{

publicvoiddoGet(h**ttpServletRequestrequest,h**ttpServletRespons孩加差景井苗没都衣末合eresponse)
throwsSe础计盐开rvletException,IOException长{

response.se省说tContentType("text/html");
灯势转及研几氢但蛋PrintWriterout=response.getWriter()慢;
this.doPost应上培能宪具盟具(request,r参杂换复算重esponse);//调用doPost方法
out联.flush();
out.close();
}
publicvoiddoPost(h**ttpServletRequestrequest,h**ttpServletResponseresponse)
throwsServletException,IOException{

response.setContentType("text/html");
PrintWriterout=response.getWriter();
List<Emp>list=newArrayList<Emp>();
EmpDaodao=newEmpDaoImp();
list=dao.queryAllEmp();//调用实现类的查询全部方法
request.setAttribute("list",list);//把查询结果放入request对象中
request.getRequestDispatcher("showAllEmp.jsp").forward(request,response);//转发到现实全部的页面
out.flush();
out.close();
}
}