一个jsp页面放着的是查询结果,每条结果后面都有一个按钮,点一下就把该条记录的id传到action然后给dao删除,我用的是hibernate。问题:在该jsp页面第一点删除可以执行就是tomcat开启后第一次删除可以成功。然后在点删除就报500错误了。。代码如下:<button value="del" onclick="javascript:window.location='<%=path %>/studentinfo/studentinfo.do?method=del&id=${stu.id}'">
删除
</button>
//这个是按钮出发的事件;dao代码:
public void del(int id) {
Session session = HibernateSessionFactory.getSession();
session.beginTransaction();
try {
//session.createQuery("from Student");
Student stu = new Student();
stu.setId(id);
session.delete(stu);
session.getTransaction().commit();
} catch (Exception e) {
e.printStackTrace();
session.getTransaction().rollback();
} finally {
HibernateSessionFactory.closeSession();
} }
再次劳驾各位,小弟没分了。。等有分的时候一定厚报大家。