首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > JAVA > Java Web开发 >

JSP+HIBERNATE有关问题

2013-09-11 
JSP+HIBERNATE问题我用JSP+HIBERNATE开发项目。Hibernate有关的类全部编译成功,并且放到了WEB-INF/classes/

JSP+HIBERNATE问题
我用JSP+HIBERNATE开发项目。
Hibernate有关的类全部编译成功,并且放到了WEB-INF/classes/mypack里。
有关Hibernate的XML文件也都配置完毕。
Hibernate包下的hibernate2.jar和LIB目录下的所有JAR都放到了项目的WEB-INF/LIB目录下。
在JSP中引用了Hibernate的持久类和逻辑类。但在启动后页面报错

HTTP   Status   500   -  

--------------------------------------------

type   Exception   report

message  

description   The   server   encountered   an   internal   error   ()   that   prevented   it   from   fulfilling   this   request.

exception  

javax.servlet.ServletException:   net/sf/hibernate/HibernateException
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:272)
javax.servlet.http.HttpServlet.service(HttpServlet.java:802)


root   cause  

java.lang.NoClassDefFoundError:   net/sf/hibernate/HibernateException
java.lang.Class.getDeclaredConstructors0(Native   Method)
java.lang.Class.privateGetDeclaredConstructors(Unknown   Source)

JSP代码如下:customer.jsp

<%@   page   import= "java.sql.*,java.util.* "   errorPage= "error.jsp "%>  

<jsp:useBean   id= "cm "   class= "mypack.Customer "   scope= "page ">

<jsp:setProperty   name= "cm "   property= "* "/>

</jsp:useBean>

<jsp:useBean   id= "cb "   class= "mypack.CustomerBean "   scope= "page "/>

<html> <body> <center>

<%  

try

{

if(cm.getId().equals(null)||cm.getId().equals( " "));

else   cb.addCourse(course);


%>

成功添加了Customer: <br>

username: <%=cm.getUsername()%>

Id: <%=cm.getId()%>

<%

}

catch(Exception   e)

{

}  

%>  


<hr>

<br> ::增加一个Customer:: <br>

<form   action= "customer.jsp "   method= "get "   name= "add ">

id: <input   type=text   name= "id "> <br>

username: <input   type=text   name= "username "> <br>

<input   type=submit   value= "submit "> <br>

</form>

<hr>

::按名字模糊查找:: <br>

<form   action= "queryCustomer.jsp "   method= "get "   name= "queryByName ">

username: <input   type=text   name= "username "> <br>

<input   type=submit   value= "query "> <br>

</form>

<hr>

::删除一个Customer:: <br>

<form   action= "deleteCustomer.jsp "   method= "get "   name= "queryByName ">

id: <input   type=text   name= "id "> <br>

<input   type=submit   value= "delete "> <br>

</form>

<hr>

<a   href=viewAll.jsp> ::查看所有Customer:: <a>

</body>

</html>  

HIBERNATE业务逻辑代码如下:
package   mypack;



import   net.sf.hibernate.*;

import   net.sf.hibernate.cfg.*;

import   java.util.*;


/**

*和Customer相关的业务逻辑

*/

public   class   CustomerBean   extends   HibernateBase

{

public   CustomerBean()throws   HibernateException

{

super();

}

/**

*增加一个Customer

*/

public   void   addCustomer(Customer   st)throws   HibernateException

{

beginTransaction();

session.save(st);  

endTransaction(true);

}


/**

*查询系统中所有的Customer,返回的是包含有Customer持久对象的Iterator。

*/

public   Iterator   getAllCustomer()throws   HibernateException

{

String   queryString   =   "select   Customer   from   Customer   as   Customer ";

beginTransaction();

Query   query   =   session.createQuery(queryString);

Iterator   it=   query.iterate();

return   it;

}


/**

*删除给定ID的Customer

*/

public   void   deleteCustomer(String   id)throws   HibernateException

{

beginTransaction();  

Customer   Customer=(Customer)session.load(Customer.class,id);  

session.delete(Customer);

endTransaction(true);

}


/**

*按Customer的名字进行模糊查找,返回的是包含有Customer持久对象的Iterator。

*/

public   Iterator   getSomeCustomer(String   name)throws   HibernateException

{

String   queryString   =   "select   c   from   Customer   as   c   where   c.username   like   :username "   ;

beginTransaction();

Query   query   =   session.createQuery(queryString);

query.setString( "username ",   "% "+name+ "% ");

Iterator   it=   query.iterate();

return   it;

}  

}  
请各位同志帮忙看下

[解决办法]
司法
[解决办法]
net/sf/hibernate/HibernateException

应该是少了某些类吧
[解决办法]
类没找到,应该是你想classpath添加的jar文件没成功,好好检查检查,另外查看你的hibernate的jar文件文件中是否有net/sf/hibernate/HibernateException这个类,如果没有说明你的hibernate版本不正确
[解决办法]
看看你hibernate的版本。
hibernate3.0:
hibernate.dialect=org.hibernate.dialect.MySQLDialect
hibernate2.0:
hibernate.dialect=net.sf.hibernate.dialect.MySQLDialect

[解决办法]
jar有问题 好好检查
[解决办法]
大侠:你好,我正在学习hibernate,和和一样,练习做网上的一个例子,出的错误也一样
下面是你提问的地方:
http://community.csdn.net/Expert/TopicView3.asp?id=5392213
我想问你最后解决没?如何解决的?
我的EMAIL:mh5188@yahoo.com.cn
QQ:14528963
[解决办法]
WEB-INF/LIB

==>

WEB-INF/lib
我的异常网推荐解决方案:The server encountered an internal error () that prevented it from fulfilling this request.,http://www.myexception.cn/java-web/317.html

热点排行