关于网友提出的“ 求大神提携,WEB实验小项目问题求解决。”问题疑问,本网通过在网上对“ 求大神提携,WEB实验小项目问题求解决。”有关的相关答案进行了整理,供用户进行参考,详细问题解答如下:
问题: 求大神提携,WEB实验小项目问题求解决。
描述: java.lang.NullPointerException
at dao.BulletinDaoImpl.delete(BulletinDaoImpl.java:46)
老是这个错误,知道是为空值,但是不知道在哪里解决
Servlet
public void doPost(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
<>
request.setCharacterEncoding("gbk");
Long id = Long.parseLong(request.getParameter("id"));
BulletinDao bulletinDao = new BulletinDaoImpl();
bulletinDao.delete(bulletinDao.get(id));
response.sendRedirect("FindServlet");
}
delete方法
public void delete(Bulletin bulletin) {
try {
session = this.getSession();
tx.begin();
session.delete(bulletin);
tx.commit();
} catch (Exception e) {
tx.rollback();
e.printStackTrace();
}
}
get方法
public Bulletin get(Long id) {
try {
session = this.getSession();
String hql = "from Bulletin where id=?";
Query query = session.createQuery(hql);
query.setLong(0, id);
return (Bulletin)query.uniqueResult();
} catch (Exception e) {
e.printStackTrace();
}
return null;
}
在页面上传递一个ID过来,已经测试有ID传过来,用的是Hibernate框架, 求解答。谢谢
以上介绍了“ 求大神提携,WEB实验小项目问题求解决。”的问题解答,希望对有需要的网友有所帮助。
本文网址链接:http://www.codes51.com/itwd/2135838.html