做了一个向数据库添加的动作,抛出严重异常,工程中用了Hibernate和ExtJs,异常如下:
严重:Servlet.service()forservletjspthrewexceptionjava.lang.NoClassDefFoundError:org/hib...
严重: Servlet.service() for servlet jsp threw exception
java.lang.NoClassDefFoundError: org/hibernate/Session
at com.family168.student.StudentDao.insert(StudentDao.java:54)
at org.apache.jsp.jsp.save_jsp._jspService(save_jsp.java:77)
at org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:803)
at org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:393)
at org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:320)
at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:266)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:803)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:230)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:175)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:128)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:104)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:261)
at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:844)
at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:581)
at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:447)
at java.lang.Thread.run(Unknown Source)
==================================================================
save.jsp源码:
<%@ page contentType="application/json;charset=utf-8"
import="com.family168.student.*"%>
<%
request.setCharacterEncoding("utf-8");
response.setCharacterEncoding("utf-8");
String id = request.getParameter("id");
String code = request.getParameter("code");
String name = request.getParameter("name");
String sex = request.getParameter("sex");
String age = request.getParameter("age");
String political = request.getParameter("political");
String origin = request.getParameter("origin");
String professional = request.getParameter("professional");
Student student = new Student();
student.setCode(code);
student.setName(name);
student.setSex(Integer.parseInt(sex));
student.setAge(Integer.parseInt(age));
student.setPolitical(political);
student.setOrigin(origin);
student.setProfessional(professional);
StudentDao dao = StudentDao.getInstance();
if (id == null || id.equals("")) {
dao.insert(student);
} else {
student.setId(Long.parseLong(id));
dao.update(student);
}
out.print("{success:true,msg:'保存成功'}");
%>
============================================================
StudentDao.java中相关的源码:
public void insert(Student student) throws Exception {
Session s = null;
Transaction t = null;
try {
s = DbUtils.getSession();
t = s.beginTransaction();
s.save(student);
t.commit();
} catch (RuntimeException e) {
e.printStackTrace();
t.rollback();
}finally{
try {
s.close();
} catch (RuntimeException e) {
e.printStackTrace();
}
}
}
==================================================================
注意:不要说我没导org.hibernate.Session这个包。我已经到过了。 展开
java.lang.NoClassDefFoundError: org/hibernate/Session
at com.family168.student.StudentDao.insert(StudentDao.java:54)
at org.apache.jsp.jsp.save_jsp._jspService(save_jsp.java:77)
at org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:803)
at org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:393)
at org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:320)
at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:266)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:803)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:230)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:175)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:128)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:104)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:261)
at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:844)
at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:581)
at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:447)
at java.lang.Thread.run(Unknown Source)
==================================================================
save.jsp源码:
<%@ page contentType="application/json;charset=utf-8"
import="com.family168.student.*"%>
<%
request.setCharacterEncoding("utf-8");
response.setCharacterEncoding("utf-8");
String id = request.getParameter("id");
String code = request.getParameter("code");
String name = request.getParameter("name");
String sex = request.getParameter("sex");
String age = request.getParameter("age");
String political = request.getParameter("political");
String origin = request.getParameter("origin");
String professional = request.getParameter("professional");
Student student = new Student();
student.setCode(code);
student.setName(name);
student.setSex(Integer.parseInt(sex));
student.setAge(Integer.parseInt(age));
student.setPolitical(political);
student.setOrigin(origin);
student.setProfessional(professional);
StudentDao dao = StudentDao.getInstance();
if (id == null || id.equals("")) {
dao.insert(student);
} else {
student.setId(Long.parseLong(id));
dao.update(student);
}
out.print("{success:true,msg:'保存成功'}");
%>
============================================================
StudentDao.java中相关的源码:
public void insert(Student student) throws Exception {
Session s = null;
Transaction t = null;
try {
s = DbUtils.getSession();
t = s.beginTransaction();
s.save(student);
t.commit();
} catch (RuntimeException e) {
e.printStackTrace();
t.rollback();
}finally{
try {
s.close();
} catch (RuntimeException e) {
e.printStackTrace();
}
}
}
==================================================================
注意:不要说我没导org.hibernate.Session这个包。我已经到过了。 展开
3个回答
展开全部
从报错内容看是找不到class,应该是DbUtils这个类找不到,少了dbutil.jar吧
更多追问追答
追问
DbUtils这个类是我自己写的,就是用来获得session的,
DAO这块我在后台测试了都没问题,就是一部署到服务器,从界面添加数据时报这个异常。
之前我没用Hibernate之前是好好的,就是将与数据库交互的方式有JDBC改成hibernate之后,出现了这么个异常。
追答
哦,你要用hibernate的session了,还用DbUtils去拿session会报错的,因为你拿的不是hibernate的session
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
StudentDao dao = StudentDao.getInstance();
这个配置了吗?
这个配置了吗?
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询