1. 程式人生 > >SSH專案報錯解決辦法

SSH專案報錯解決辦法

遇到最常見的問題:

JAVA web專案中的no result defined for action result input

錯誤 產生這個錯誤的原因:Action中的屬性值為空的時候,Struts2的預設攔截器會報錯,但是又找不到input的Result,不能夠把錯誤返回,所以報這種錯誤。 1、validate方法沒有通過(表單驗證看看有沒有重名,導致js檔案載入過慢); 2、頁面元素中有重新命名時,但後臺action類的對應的接收此同名引數的是變數而沒有寫成陣列 3、配置檔案中result 返回.jsp出現錯誤(多了空格、或者沒有介面) 4、對應Action中沒有返回值,或者返回值出錯

1.MyEclipse報錯:Multiple markers at this line - The type java.io.ObjectInputStream cannot be resolved.

1.出錯原因 網上查了以後,說是因為JDK版本太高的問題 2.修改 window->preference->Java->Installed JREs->選擇低版本的JDK->ok ps:這裡由於我只裝了JDK1.8,所以選擇可以MyEclipse自己的JDK(即Sun JDK 1.6.0_13)

在這裡插入圖片描述

2.eclipse,myeclipse匯入工程報:javax.servlet.jsp.JspException cannot be resolved to a type 3.Eclipse中報錯The type javax.servlet.http.HttpServletResponse cannot be resolved 2和3解決辦法: 1.在工程中新增jsp-api.jar包,tomcat的安裝目錄中就有 右擊專案—》Build Path ----》Configure Build Path ,點選Java Build Path,選中右側Libraries,點選Add External JARs選擇tomcat安裝目錄下的jsp-api.jar包 2.右鍵專案Properties-------->Targeted Runtimes 把Tomcat勾上

4.Multiple annotations found at this line: 解決辦法 Multiple annotations found at this line: - schema_reference.4: Failed to read schema document ‘http://www.springframework.org/schema/beans/ spring-beans-3.1.xsd’, because 1) could not find the document; 2) the document could not be read; 3) the root element of the document is not xsd:schema
. - cvc-elt.1: Cannot find the declaration of element ‘beans’.

如上,在使用eclipse構建基於maven的springmvc 工程時,報上面的錯誤

如下為spring的配置: 在這裡插入圖片描述 在這裡插入圖片描述

如果版本沒有錯的話,把約束剪下然後重新貼上,Ctrl+S,就OK啦

5.org.springframework.dao.InvalidDataAccessApiUsageException問題解決與分析

<bean id="transactionManager"
    class="org.springframework.orm.hibernate4.HibernateTransactionManager">
    <property name="sessionFactory" ref="sessionFactory" />
</bean>

<!-- 配置事務通知屬性 -->
<tx:advice id="txAdvice" transaction-manager="transactionManager">
    <!-- 定義事務傳播屬性 -->
    <tx:attributes>
        <!-- 增 -->
        <tx:method name="insert*" propagation="REQUIRED" />
        <tx:method name="save*" propagation="REQUIRED" />
        <tx:method name="add*" propagation="REQUIRED" />
        <tx:method name="new*" propagation="REQUIRED" />
        <tx:method name="create*" propagation="REQUIRED" />
        <!-- 刪 -->
        <tx:method name="remove*" propagation="REQUIRED" />
        <tx:method name="delete*" propagation="REQUIRED" />
        <!-- 改 -->
        <tx:method name="update*" propagation="REQUIRED" />
        <tx:method name="edit*" propagation="REQUIRED" />
        <tx:method name="set*" propagation="REQUIRED" />
        <tx:method name="change*" propagation="REQUIRED" />
        <!-- 查 -->
        <tx:method name="get*" propagation="REQUIRED" read-only="true" />
        <tx:method name="find*" propagation="REQUIRED" read-only="true" />
        <tx:method name="load*" propagation="REQUIRED" read-only="true" />
        <tx:method name="*" propagation="REQUIRED" read-only="true" />
    </tx:attributes>
</tx:advice>


<!-- 配置事務切面 -->
<aop:config>
    <aop:pointcut id="serviceOperation"
        expression="execution(* cn.jkstudio.*.service.*.*.*(..))" />
    <aop:advisor advice-ref="txAdvice" pointcut-ref="serviceOperation" />
</aop:config>

好好看事務的配置有沒有錯,如果能確定沒有錯,一般是配置事務切面的地方對包路徑寫的有問題: 檢查expression=“execution(* cn.jkstudio..service...(…))” 第一個 * 表示方法返回值型別可以為任意型別 第二個 * 表示cn.jkstudio包下面的任意包 第三個 * 表示service包下面的任意包 第四個 * 表示service.任意包 下面的任意一個類 第五個 * 表示service.任意包.任意類下面的任意一個方法 後面小括號裡面的兩個 … 表示該方法可以有0個或多個引數

6.org.apache.jasper.JasperException…(line:XX, column: XX) quote symbol expected和處理辦法

quote symbol就是引號

放大你的眼睛,看看控制檯輸出的行數,找到JSP頁面,好好檢查@@@@!!@!!!!!!!!!@@@@

7.ssh框架org.springframework.dao.InvalidDataAccessApiUsageException錯誤

在使用ssh框架做使用者的儲存的時候呼叫了save方法,發生上面的錯誤; 原因是在service中沒有加入事務註解;可以再applicationContext.xml中進行對事務的配置:如下

<tx:annotation-driven transaction-manager=“transactionManager”/> 在service中加入註解:@Transactional可以在方法上加也可以在類上面加。

8.解決Spring4+Hibernate4遇到的 Write operations are not allowed in read-only mode (FlushMode.MANUAL)

一些測試方法: Dao: public class TestDao {

/** 儲存 */
@Test
public void save() {
	ApplicationContext ac = new ClassPathXmlApplicationContext("beans.xml");
	IElecTextDao elecTextDao = (IElecTextDao) ac.getBean("");
	ElecText elecText = new ElecText();
	elecText.setTextName("測試Dao名稱");
	elecText.setTextDate(new Date());
	elecText.setTextRemark("測試Dao備註");
	elecTextDao.save(elecText);
}

/** 更新 */
@Test
public void update() {
	ApplicationContext ac = new ClassPathXmlApplicationContext("beans.xml");
	IElecTextDao elecTextDao = (IElecTextDao) ac.getBean("");
	ElecText elecText = new ElecText();
	elecText.setTextID("402881e442599916014259991c450001");
	elecText.setTextName("更新名稱");
	elecText.setTextDate(new Date());
	elecText.setTextRemark("更新備註");
	elecTextDao.update(elecText);
}

/** 使用主鍵ID查詢物件 */
@Test
public void findObjectById() {
	ApplicationContext ac = new ClassPathXmlApplicationContext("beans.xml");
	IElecTextDao elecTextDao = (IElecTextDao) ac.getBean("");
	Serializable id = "402881e4425a729301425a734c2a0001";
	ElecText elecText = elecTextDao.findObjectByID(id);
	System.out.println(elecText.getTextName() + "    "
			+ elecText.getTextDate() + "    " + elecText.getTextRemark());
}

/** 刪除(使用1個主鍵ID和多個主鍵ID的陣列) */
@Test
public void deleteObjectByIDs() {
	ApplicationContext ac = new ClassPathXmlApplicationContext("beans.xml");
	IElecTextDao elecTextDao = (IElecTextDao) ac.getBean("");
	// Serializable [] ids =
	// {"402881e442599916014259991c450001","402881e44259d1c0014259d1c48b0001"};
	Serializable ids = "402881e44259de3a014259de40e40001";
	elecTextDao.deleteBojectByIDs(ids);
}

/** 刪除(將物件封裝成集合,使用集合刪除集合中存放的所有物件) */
@Test
public void deleteObjectByCollection() {
	ApplicationContext ac = new ClassPathXmlApplicationContext("beans.xml");
	IElecTextDao elecTextDao = (IElecTextDao) ac.getBean("");
	List<ElecText> list = new ArrayList<ElecText>();
	ElecText elecText1 = new ElecText();
	elecText1.setTextID("402881e44259dfc5014259dfcaa10001");
	ElecText elecText2 = new ElecText();
	elecText2.setTextID("402881e44259e338014259e36de70001");
	list.add(elecText1);
	list.add(elecText2);
	elecTextDao.deleteObjectByCollection(list);
}

} Service: public class TestService {

/** 儲存 */
@Test
public void save() {
	ApplicationContext ac = new ClassPathXmlApplicationContext("beans.xml");
	IElecTextService elecTextService = (IElecTextService) ac.getBean("");
	ElecText elecText = new ElecText();
	elecText.setTextName("測試Service名稱");
	elecText.setTextDate(new Date());
	elecText.setTextRemark("測試Service備註");
	elecTextService.save(elecText);
}

} 二級快取: public class TestHibernateCache {

/**測試類級別的二級快取*/
@Test
public void testClassCache(){
	Configuration configuration = new Configuration();
	//預設載入類路徑下的hibernate.cfg.xml,同時載入對映檔案
	configuration.configure();
	SessionFactory sf = configuration.buildSessionFactory();
	
	Session s = sf.openSession();
	Transaction tr = s.beginTransaction();
	
	ElecSystemDDL ddl1 = (ElecSystemDDL)s.get(ElecSystemDDL.class, 15);//存在
	
	ElecSystemDDL ddl2 = (ElecSystemDDL)s.get(ElecSystemDDL.class, 15);//沒有,從Session的一級快取中
	
	tr.commit();
	s.close();
	/*******************************************/
	s = sf.openSession();
	tr = s.beginTransaction();
	
	ElecSystemDDL ddl3 = (ElecSystemDDL)s.get(ElecSystemDDL.class, 15);//沒有,從SessionFactory的二級快取中,存放的散裝資料
	
	tr.commit();
	s.close();
	
}

/**測試查詢級別的二級快取*/
@Test
public void testQueryCache(){
	Configuration configuration = new Configuration();
	//預設載入類路徑下的hibernate.cfg.xml,同時載入對映檔案
	configuration.configure();
	SessionFactory sf = configuration.buildSessionFactory();
	
	Session s = sf.openSession();
	Transaction tr = s.beginTransaction();
	
	Query query1 = s.createQuery("from ElecSystemDDL o where o.keyword = '性別'");
	query1.setCacheable(true);
	query1.list();//產生select語句
	
	tr.commit();
	s.close();
	/*******************************************/
	s = sf.openSession();
	tr = s.beginTransaction();
	
	Query query2 = s.createQuery("from ElecSystemDDL o where o.keyword = '性別'");
	query2.setCacheable(true);
	query2.list();//產生select語句
	
	tr.commit();
	s.close();
	
}

}

JBPM public class TestHibernateJbpm {

/**
 * 生成JBPM的18張表
 * <property name="hibernate.hbm2ddl.auto">update</property>
 * */
@Test
public void createJbpm(){
	ApplicationContext ac = new ClassPathXmlApplicationContext("beans.xml");
	SessionFactory sf = (SessionFactory) ac.getBean("sessionFactory");
	System.out.println("SessionFactory:"+sf);
}

/**測試流程引擎物件*/
@Test
public void testProcessEngine(){
	ApplicationContext ac = new ClassPathXmlApplicationContext("beans.xml");
	ProcessEngine processEngine = (ProcessEngine)ac.getBean("processEngine");
	System.out.println("PorcessEngine:"+processEngine);
}

}

$%7BpageContext.request.contextPath%7D

9.Unable to create requested service [org.hibernate.engine.spi.CacheImple 在使用Hibernate4做二級快取的測試(HashtableCacheProvider)時,會報如下異常: 1.

在這裡插入圖片描述

2.在org.hibernate.cache包下面缺少很多class檔案,如HashtableCacheProvider.class等,你可以將hibernate3中org.hibernate.cache下面的檔案拷貝到hibernate4的核心jar包下,或者使用Hibernate3的核心jar包。

10.Exception in thread “main” java.lang.Error: Unresolved compilation problems 解決方案

找了很久,終於找到原因了,下了個commons jar包, 然後按如下步驟:在Package Explore內 對應的工程上 單擊右鍵;彈出右鍵選單上單擊“Build Path->Configure Build Path”,在彈出的對話方塊上 單擊“Libararies->add External JARS” 選擇上你的jar包所在位置就可以了

11.org.hibernate.engine.jdbc.spi.SqlExceptionHelper - Table ‘XXX’ doesn’t exist

在專案的hibernate.cfg.xml中,我配置好xml後讓hibernate自動在mysql建表 update   可是,執行的時候報錯“org.hibernate.engine.jdbc.spi.SqlExceptionHelper - Table ‘XXX’ doesn’t exist”。可見,hibernate並沒有幫我們自動建立資料庫表文件。於是我手動在資料庫中建立表,然後在跑一次程式,果然沒有問題了。      原因分析:   資料庫方言配置出現問題了,我們需要配置更高版本的資料庫方言,具體如下: hibernate-5.0.7中使用的方言

<property name="hibernate.dialect">org.hibernate.dialect.MySQLDialect</property>

Hibernate-5.2.10 使用的方言需要升級   解決辦法:   在hibernate.cfg.xml中配置 SQL dialect方言。支援mysql高版本的建表。將

<!--<property name="hibernate.dialect">org.hibernate.dialect.MySQLDialect</property>-->
<property name="hibernate.dialect">org.hibernate.dialect.MySQL5Dialect</property>

這樣,hibernate就可以自動來建立資料庫表了。

12.omcat在 myeclipse中第一次啟動時報錯:Address already in use: JVM_Bind:80804

問題:剛安裝的tomcat在 myeclipse中第一次啟動時報錯:Address already in use: JVM_Bind:8080 原因:tomcat已經在使用,後來發現已經在控制面板=》管理工具=》服務中啟動了tomcat的服務,關閉後就可以啟動成功啟動tomcat了。

13.org.activiti.engine.ActivitiException: Couldn’t deserialize object in variable ‘application’

1、遇到工作流的問題第一個想到的,我覺得就是在新增流程變數的的時候,你的實體類有沒有實現序列化介面 2、然後,再看其他的問題 3.今天遇到了這個問題,其他的都實現了序列化介面,以為不是這個問題,由於我的專案中,有一個taskView類(申請和task類的實體類),這個我是沒有實現序列化的,原本以為是不用實現的,但是後來通過debug除錯後發現問題就是出現在這裡。 4.實現序列化介面後,問題就解決了。

解決辦法:注意類與類之間的關係,之間的強轉,介面的泛型是否有寫正確。