| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 909 人关注过本帖
标题:[求助]Hibernate问题--在tomcat运行时总是提示NoClassDefFound的错误,
取消只看楼主 加入收藏
kingmax432
Rank: 1
等 级:新手上路
帖 子:1
专家分:0
注 册:2006-9-6
收藏
 问题点数:0 回复次数:0 
[求助]Hibernate问题--在tomcat运行时总是提示NoClassDefFound的错误,

小弟初学hibernate遇上问题 请各位援手
在tomcat运行时总是提示NoClassDefFound的错误,用jbilder2006&Eclipse3.2+myEclipse5.0都试过
java.lang.NoClassDefFoundError
com.hibernate.HibernateSearch.dosearch(HibernateSearch.java:41)
com.struts.action.IndexAction.execute(IndexAction.java:45)
org.apache.struts.action.RequestProcessor.processActionPerform(RequestProcessor.java:484)
org.apache.struts.action.RequestProcessor.process(RequestProcessor.java:274)
org.apache.struts.action.ActionServlet.process(ActionServlet.java:1482)
org.apache.struts.action.ActionServlet.doPost(ActionServlet.java:525)
javax.servlet.http.HttpServlet.service(HttpServlet.java:709)
javax.servlet.http.HttpServlet.service(HttpServlet.java:802)

不清楚问题原因. 小弟将源码内容贴入,请各位指教 谢谢 可能有些文件是不完整的请下载附件 没毒!

下面时源码内容:

hibernate.cfg.xml文件为:
<?xml version='1.0' encoding='UTF-8'?>
<!DOCTYPE hibernate-configuration PUBLIC
"-//Hibernate/Hibernate Configuration DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd">

<!-- Generated by MyEclipse Hibernate Tools. -->
<hibernate-configuration>

<session-factory>
<property name="connection.username">sa</property>
<property name="connection.url">
jdbc:microsoft:sqlserver://127.0.0.1:1433;databasename=train
</property>
<property name="dialect">
org.hibernate.dialect.SQLServerDialect
</property>
<property name="myeclipse.connection.profile">mssql</property>
<property name="connection.password">1234</property>
<property name="connection.driver_class">
com.microsoft.jdbc.sqlserver.SQLServerDriver
</property>
<mapping resource="com/hibernate/UserList.hbm.xml" />

</session-factory>

</hibernate-configuration>

UserList.hbm.xml文件为:
<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
<!--
Mapping file autogenerated by MyEclipse - Hibernate Tools
-->
<hibernate-mapping>
<class name="com.hibernate.UserList" table="userList" schema="dbo" catalog="train">
<id name="id" type="java.lang.Integer">
<column name="id" />
<generator class="assigned" />
</id>
<property name="userName" type="java.lang.String">
<column name="userName" length="20" not-null="true" />
</property>
<property name="userPwd" type="java.lang.String">
<column name="userPwd" length="30" />
</property>
</class>
</hibernate-mapping>


HibernateSearch类的内容:
package com.hibernate;

import org.hibernate.*;
import org.hibernate.cfg.*;
import org.apache.commons.logging.*;
import java.util.*;


public class HibernateSearch {
public HibernateSearch() {
}
Session s=null;
boolean result=false;
Transaction tx=null;
public static Log log=LogFactory.getLog(HibernateSearch.class);
public boolean dosearch(String strsql) throws HibernateException
{
try
{
s=HibernateUtil.curSession();
tx=s.beginTransaction();
List rs=s.createQuery(strsql).list();
if(rs.size()!=0)
{
result=true;
}
else
{
result=false;
}
tx.commit();

}
catch(HibernateException ex)
{
log.error("错误",ex);
throw ex;
}
finally
{
HibernateUtil.closeSession();
}
return result;
}

}

HibernateUtil类的内容:
package com.hibernate;

import org.hibernate.*;
import org.hibernate.cfg.*;

public class HibernateUtil {
public HibernateUtil() {
}

private static final SessionFactory sf;
public static final ThreadLocal tl=new ThreadLocal();

static
{
try
{
sf=new Configuration().configure().buildSessionFactory();
}
catch(Throwable ex)
{
throw new ExceptionInInitializerError(ex);
}
}

public static Session curSession()
{
Session curSession=(Session)tl.get();
if(curSession==null)
{
curSession=sf.openSession();
tl.set(curSession);

}
return curSession;
}
public static void closeSession()
{
Session curSession=(Session)tl.get();
if(curSession!=null)
{
curSession.close();
}
tl.set(null);
}
}

UserList映射类内容为:
package com.hibernate;

/**
* UserList generated by MyEclipse - Hibernate Tools
*/

public class UserList implements java.io.Serializable {


// Fields

private Integer id;
private String userName;
private String userPwd;


// Constructors

/** default constructor */
public UserList() {
}

/** minimal constructor */
public UserList(Integer id, String userName) {
this.id = id;
this.userName = userName;
}

/** full constructor */
public UserList(Integer id, String userName, String userPwd) {
this.id = id;
this.userName = userName;
this.userPwd = userPwd;
}


// Property accessors

public Integer getId() {
return this.id;
}

public void setId(Integer id) {
this.id = id;
}

public String getUserName() {
return this.userName;
}

public void setUserName(String userName) {
this.userName = userName;
}

public String getUserPwd() {
return this.userPwd;
}

public void setUserPwd(String userPwd) {
this.userPwd = userPwd;
}
}

IndexAction类内容为:
package com.struts.action;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.apache.struts.action.Action;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;
import com.struts.form.IndexForm;
import com.hibernate.*;

public class IndexAction extends Action {

public ActionForward execute(ActionMapping mapping, ActionForm form,
HttpServletRequest request, HttpServletResponse response) {
IndexForm indexForm = (IndexForm) form;// TODO Auto-generated method stub
String name=indexForm.getUserName();
String pwd=indexForm.getUserPwd();
ActionForward f=null;
HibernateSearch hs=new HibernateSearch();
String strsql="from userList where userName='"+name+"' and userPwd='"+pwd+"'";
if(hs.dosearch(strsql))
{
f=mapping.findForward("sucess");
}
else
{
f=mapping.findForward("fail");
}
return f;
}
}


IndexForm类内容为
package com.struts.form;

import javax.servlet.http.HttpServletRequest;
import org.apache.struts.action.ActionErrors;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionMapping;


public class IndexForm extends ActionForm {


private String userName;


private String userPwd;



public ActionErrors validate(ActionMapping mapping,
HttpServletRequest request) {
// TODO Auto-generated method stub
return null;
}


public void reset(ActionMapping mapping, HttpServletRequest request) {
// TODO Auto-generated method stub
}


public String getUserName() {
return userName;
}


public void setUserName(String userName) {
this.userName = userName;
}


public String getUserPwd() {
return userPwd;
}


public void setUserPwd(String userPwd) {
this.userPwd = userPwd;
}
}

Index.jsp内容:(Sucess.jsp和Fail.jsp只是简单的输出显示 这里就不赘述)
<%@ page language="java"%>
<%@ taglib uri="http://jakarta.apache.org/struts/tags-bean" prefix="bean"%>
<%@ taglib uri="http://jakarta.apache.org/struts/tags-html" prefix="html"%>

<html>
<head>
<title>JSP for IndexForm form</title>
</head>
<body>
<html:form action="/index">
userName : <html:text property="userName"/><html:errors property="userName"/><br/>
userPwd : <html:text property="userPwd"/><html:errors property="userPwd"/><br/>
<html:submit/><html:cancel/>
</html:form>
</body>
</html>

struts-config.xml内容:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE struts-config PUBLIC "-//Apache Software Foundation//DTD Struts Configuration 1.1//EN" "http://jakarta.apache.org/struts/dtds/struts-config_1_1.dtd">

<struts-config>
<data-sources />
<form-beans >

<form-bean name="indexForm" type="com.struts.form.IndexForm" />

</form-beans>

<global-exceptions />
<global-forwards/>
<action-mappings >

<action
attribute="indexForm"
input="Index.jsp"
name="indexForm"
path="/index"
scope="request"
type="com.struts.action.IndexAction">
<forward name="sucess" path="/Sucess.jsp" />
<forward name="fail" path="/Fail.jsp" />
</action>

</action-mappings>

<message-resources parameter="com.struts.ApplicationResources" />
</struts-config>

数据库内容:

create table userList
(id int,userName varchar(20),userPwd varchar(30))

/*数据库名为train 用户名为sa 密码为1234 */


ZhWjSbHC.rar (2.28 KB) [求助]Hibernate问题--在tomcat运行时总是提示NoClassDefFound的错误,


搜索更多相关主题的帖子: 提示 运行 Hibernate tomcat 
2006-09-06 13:17
快速回复:[求助]Hibernate问题--在tomcat运行时总是提示NoClassDefFound的错误,
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.025728 second(s), 9 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved