jsp+javaBean+hibernate 執行時報錯,大家幫著看看!
錯誤是:
root cause
java.lang.ExceptionInInitializerError
test.Student.selectHBM(test.java:262)
org.apache.jsp.register_jsp._jspService(register_jsp.java:150)
org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:133)
javax.servlet.http.HttpServlet.service(HttpServlet.java:856)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:311)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:301)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:248)
javax.servlet.http.HttpServlet.service(HttpServlet.java:856)
程式碼是
public boolean selectHBM() throws Exception {
Session session = HibernateUtil.currentSession(); //就是這裡出錯
try {
String queryString = "select test.Student from test.Student as stu where stu.userid='"+userid+"'";
Query query = session.createQuery(queryString);
Iterator it = query.iterate();
if(it.hasNext()){
Student stu=(Student)it.next();
username = stu.getUsername();
sex = stu.getSex();
birthday = stu.getBirthday();
email = stu.getEmail();
address = stu.getAddress();
phone = stu.getPhone();
cardnumber = stu.getCardnumber();
regip = stu.getRegip();
regdate = stu.getRegdate();
return true;
}else{
return false;
}
} catch (Exception he) {
throw new Exception(he);
} finally {
HibernateUtil.closeSession();
}
}
這個方法主要用來查詢某個編號的學生,有的話初始化他
下面這個工具類也沒錯啊,編譯透過了
import java.io.InputStream;
import java.util.Properties;
package test;
import net.sf.hibernate.*;
import net.sf.hibernate.cfg.*;
public class HibernateUtil {
private static final SessionFactory sessionFactory;
static {
try {
sessionFactory = new Configuration().configure().buildSessionFactory();
} catch (HibernateException ex) {
throw new RuntimeException("Exception building SessionFactory: " + ex.getMessage(), ex);
}
}
public static final ThreadLocal session = new ThreadLocal();
public static Session currentSession() throws HibernateException {
Session s = (Session) session.get();
// Open a new Session, if this Thread has none yet
if (s == null) {
s = sessionFactory.openSession();
session.set(s);
}
return s;
}
public static void closeSession() throws HibernateException {
Session s = (Session) session.get();
session.set(null);
if (s != null)
s.close();
}
}
我分析是執行的時候找不到需要的hibernate類庫
但是我把hibernate所需要的包全部複製到 web-inf\lib裡了啊
hibernate所需要的配置檔案hibernate.cfg.xml和Student_hbm.xml也都在web-inf\class下啊
那位朋友指點一下
root cause
java.lang.ExceptionInInitializerError
test.Student.selectHBM(test.java:262)
org.apache.jsp.register_jsp._jspService(register_jsp.java:150)
org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:133)
javax.servlet.http.HttpServlet.service(HttpServlet.java:856)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:311)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:301)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:248)
javax.servlet.http.HttpServlet.service(HttpServlet.java:856)
程式碼是
public boolean selectHBM() throws Exception {
Session session = HibernateUtil.currentSession(); //就是這裡出錯
try {
String queryString = "select test.Student from test.Student as stu where stu.userid='"+userid+"'";
Query query = session.createQuery(queryString);
Iterator it = query.iterate();
if(it.hasNext()){
Student stu=(Student)it.next();
username = stu.getUsername();
sex = stu.getSex();
birthday = stu.getBirthday();
email = stu.getEmail();
address = stu.getAddress();
phone = stu.getPhone();
cardnumber = stu.getCardnumber();
regip = stu.getRegip();
regdate = stu.getRegdate();
return true;
}else{
return false;
}
} catch (Exception he) {
throw new Exception(he);
} finally {
HibernateUtil.closeSession();
}
}
這個方法主要用來查詢某個編號的學生,有的話初始化他
下面這個工具類也沒錯啊,編譯透過了
import java.io.InputStream;
import java.util.Properties;
package test;
import net.sf.hibernate.*;
import net.sf.hibernate.cfg.*;
public class HibernateUtil {
private static final SessionFactory sessionFactory;
static {
try {
sessionFactory = new Configuration().configure().buildSessionFactory();
} catch (HibernateException ex) {
throw new RuntimeException("Exception building SessionFactory: " + ex.getMessage(), ex);
}
}
public static final ThreadLocal session = new ThreadLocal();
public static Session currentSession() throws HibernateException {
Session s = (Session) session.get();
// Open a new Session, if this Thread has none yet
if (s == null) {
s = sessionFactory.openSession();
session.set(s);
}
return s;
}
public static void closeSession() throws HibernateException {
Session s = (Session) session.get();
session.set(null);
if (s != null)
s.close();
}
}
我分析是執行的時候找不到需要的hibernate類庫
但是我把hibernate所需要的包全部複製到 web-inf\lib裡了啊
hibernate所需要的配置檔案hibernate.cfg.xml和Student_hbm.xml也都在web-inf\class下啊
那位朋友指點一下
相關文章
- 這個程式就是執行不料。真著急。。大家幫幫我。。
- 安裝Jive進行資料庫設定時報錯,請大家都我看看。資料庫
- 安裝是遇到錯誤,大家幫我看看,謝謝
- 幫我看看我的jmsBean,執行測試時出錯!Bean
- yii執行phpunit時報錯PHP
- 大家幫幫忙,看看這個SQL怎麼寫!SQL
- 求助:SimpleJdonFrameworkTest+JBOSS配置,執行出錯。banq老師幫忙看看Framework
- 執行dbca時報錯:Xlib:No protocol specifiedProtocol
- php5.3.3呼叫https的wsdl,出現錯誤,請大家幫忙看看PHPHTTP
- [求助] 在 Linux 下執行 web 自動化測試,pytest 報錯了,大家幫忙看看這是啥問題啊?LinuxWeb
- 監聽Session事件不能編譯,大家幫忙看看Session事件編譯
- 大家幫我看看,下面寫的是否對。(web.xml)WebXML
- jf6.2初學者問題,請大家幫忙看看
- 一個執行緒的問題。請大俠進來幫幫忙看看執行緒
- 新建外掛,提示沒有許可權,請大家幫看看。
- 安裝出錯,請幫忙看看(轉)
- Centos 6.4安裝rac,執行root.sh時報錯CentOS
- 我的第一個entity Ejb就出錯!大家幫幫忙
- 執行時報錯RuntimeError: expected device cpu but got device cuda:0ErrordevGo
- Couldn't be opened because you don't have permission to view it 執行時報錯View
- eclipse 打war包後執行時報 cas.client 錯誤Eclipseclient
- apk執行時報錯: java lang UnsatisfiedLinkError dalvik system PathClassLoadeAPKJavaError
- npm 執行時報錯“因為在此係統上禁止執行指令碼”解決辦法NPM指令碼
- IDEA 執行 XXX 時報錯命令列過長,縮短命令列並重新執行Idea命令列
- 執行資料庫克隆時報ORA-01103錯誤資料庫
- 大家幫忙看看下面的需求第3和第4能實現不??
- 線上等,幫忙看看什麼錯,在mysql下跑MySql
- JBoss報錯,org.xml.sax.SAXParseException?老大幫我看看XMLException
- 懂ibatis的大俠幫小弟看看錯在哪了BAT
- 執行 PHP artisan migrate 時報長度錯誤的解決辦法?PHP
- 執行npm install 和 yarn 命令時報錯找不到python環境NPMYarnPython
- 面試題,大家也可以看看(piner)面試題
- SQLServer對錶進行CDC捕捉時報錯SQLServer
- 執行root.sh 時報錯Failed to upgrade Oracle Cluster Registry configurationAIOracle
- 幫我看看如何解決?
- 安裝JPETSTORE出錯,請幫忙看看是哪出了問題.
- 我的面試題,大家也可以看看面試題
- Oracle在UNIX上實施的新書就要面市,還請大家幫忙看看,書名怎麼定合適?謝謝大家!Oracle新書