基於Struts+Hibernate開發過程中遇到的錯誤

來源:互聯網
上載者:User

標籤:struts hibernate 調試

1.import  javax.servlet.http.HttpServletRequest 匯入包出錯匯入包出錯,通常是包未引入,HttpServletRequest包是瀏覽器通過http發出的請求, 需要將tomcat/lib 目錄下的 servlet-api.jar匯入。但是匯入後仍然不行,重啟eclipse也無法讓他生效最後通過 project -clean來生效的。
2.JSP介面中加入了form標籤後就報錯
解決辦法:將tomcat/lib目錄下的el-api,ecj-4.3.1jre拷貝過來了
3.使用<c:forEach>標籤,報錯 Failed to load or instantiate TagLibraryValidator class
首先在jsp介面開頭添加檔案<%@taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>然後在工程目錄下WEB-INF/lib目錄下添加servlet-api.jar和standard.jar
4.Abandoned connection cleanup thread] but has failed to stop it. This is very likely to create a memo每次啟動tomcat,沒有關閉就啟動,tomcat報記憶體泄露。解決就是關閉Eclipse,重啟電腦。之後每次啟動tomcat都是關閉後再啟動。
5.使用MySQL資料庫。root作為串連名,串連一段時間後出現串連被拒絕的情況預設root使用者不支援遠端控制,在mysql控制台更改了root許可權,仍然不起作用。最後使用了 navicat(mysql 視覺化檢視)建立了一個新使用者,重新設定串連。
6.資料庫表a,前台向a表寫入一條資料,立即查詢,發現沒有表a沒有更新。而查看資料庫伺服器中的表a,資料已經更新。但在myeclipse中重新串連資料庫後。再查詢時,資料得到更新。查詢方法是使用hibernate自動產生的daopublic List findByProperty(String propertyName, Object value) {
log.debug("finding Product instance with property: " + propertyName
+ ", value: " + value);
try {
String queryString = "from Product as model where model."
+ propertyName + "= ?";
Query queryObject = getsession().createQuery(queryString);
queryObject.setParameter(0, value);
return queryObject.list();
} catch (RuntimeException re) {
log.error("find by property name failed", re);
throw re;
}
}
問題就是出現在session上。hibernate架構操作資料庫是通過org.hibernate.Session來實現的。而Session是由org.hibernate.SessionFactory來管理的。Configuration conf=new Configuration().configure();//需要每次重新建立配置串連org.hibernate.SessionFactory sessionFactory=conf.buildSessionFactory();Session session=sessionFactory.openSession();
而自動產生的dao檔案中getsession()方法中只有public class BaseHibernateDAO implements IBaseHibernateDAO {
public Session getSession() {
return HibernateSessionFactory.getSession();
}
}




聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.