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框架, 求解答。谢谢
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框架, 求解答。谢谢
解决方案 »
- JQuery,Ajax与数据库交互(下拉选择框)
- myeclipse里配置tomcat始终报错。
- 基于spring security的权限控制
- 高分求教Hibernate保存失效
- 一个Ajax的问题,大家讨论一下
- 请教高手:在编写的定时发送邮件的程序中出现的错误
- 一个非常初级的问题,请教
- struts连接池配置,struts_config已经配置完毕,请问我要怎样做才知道连接成功?
- 请问:jsp中怎么用中文字符? 我输入中文时怎么会显示乱码?
- [求助]一个关于读取文本数据的问题
- (java apache cxf)80分请教cxf发布webservices的异常问题。
- JSP的JavaBean应该放在哪个目录
public Bulletin get(Long id) {
session = this.getSession();
Bulletin bulletin=null;
String hql = "from Bulletin where id=?";
try {
Query query = session.createQuery(hql);
query.setLong(0, id);
bulletin = (Bulletin)query.uniqueResult();
} catch (Exception e) {
e.printStackTrace();
}
return bulletin;
}
把项目发来膜拜一下可以不?[email protected]
if(bulletinDao.get(id)!=null && !bulletinDao.get(id).equals("") ){
bulletinDao.delete(bulletinDao.get(id));
}