JSP教程之整合hibernate持久層1(2)_JSP教程
教程Tag:暫無Tag,歡迎添加,賺取U幣!
推薦:Spring學習基礎---與Struts整合《Spring開發指南》只寫了一種與struts整合的方法,另一種到Spring2.0 Demo自帶的Doc中查找到Action直接繼承ActionSupport。詳細信息: TointegrateyourStrutsapplicationwithSpring,youhavetwooptions: ConfigureSpringtomanageyourActionsasbeans,usingtheCo
原來包含很多復雜內容的applicationContext.xml也拷貝一份applicationContext2.xml,刪除和JPetStore相關的內容,留下通用的部分:
<?xml version="1.0" encoding="UTF-8"?> <!-- - Application context definition for JPetStore’s business layer. - Contains bean references to the transaction manager and to the DAOs in - dataAccessContext-local/jta.xml (see web.xml’s "contextConfigLocation"). --> <beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:aop="http://www.springframework.org/schema/aop" xmlns:tx="http://www.springframework.org/schema/tx" xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop.xsd http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx.xsd"> <bean id="propertyConfigurer" class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer"> <property name="locations"> <list> <value>WEB-INF/mail.properties</value> <value>WEB-INF/jdbc.properties</value> </list> </property> </bean> <aop:config> <aop:advisor pointcut="execution(* *..PetStoreImpl.*(..))" advice-ref="txAdvice"/> </aop:config> <!-- Transaction advice definition, based on method name patterns. Defaults to PROPAGATION_REQUIRED for all methods whose name starts with "insert" or "update", and to PROPAGATION_REQUIRED with read-only hint for all other methods. --> <tx:advice id="txAdvice"> <tx:attributes> <tx:method name="insert*"/> <tx:method name="update*"/> <tx:method name="*" read-only="true"/> </tx:attributes> </tx:advice> </beans> |
在Struts配置文件中增加自己的Action如下:
<action path="/showusers" type="srx.test.struts.action.UserAction"> <forward name="success" path="/WEB-INF/jsp/srx/test/hibernate/showusers.jsp"/> </action> |
web.xml中使用action作為*。do處理的servlet而不是默認的petstore。
并注釋掉名字為petstore,remoting的servlet。如下:
<web-app xmlns="http://java.sun.com/xml/ns/j2ee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd" version="2.4"> <display-name>Spring JPetStore</display-name> <description>Spring JPetStore sample application</description> <context-param> <param-name>webAppRootKey</param-name> <param-value>petstore.root</param-value> </context-param> <context-param> <param-name>log4jConfigLocation</param-name> <param-value>/WEB-INF/log4j.properties</param-value> </context-param> <context-param> <param-name>contextConfigLocation</param-name> <param-value> /WEB-INF/dataAccessContext-hibernate.xml </param-value> </context-param> <listener> <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class> </listener> <servlet> <servlet-name>action</servlet-name> <servlet-class>org.apache.struts.action.ActionServlet</servlet-class> <load-on-startup>3</load-on-startup> </servlet> <servlet-mapping> <servlet-name>action</servlet-name> <url-pattern>*.do</url-pattern> </servlet-mapping> ... </web-app> |
分享:解讀Spring異常處理配置Spring異常處理之需要增加一個bean的配置: !--ExceptionResolver-- beanid=exceptionResolverclass=org.springframework.web.servlet.handler.SimpleMappingExceptionResolver propertyname=defaultErrorView value/exception/failure/value /prop
相關JSP教程:
- jsp response.sendRedirect不跳轉的原因分析及解決
- JSP指令元素(page指令/include指令/taglib指令)復習整理
- JSP腳本元素和注釋復習總結示例
- JSP FusionCharts Free顯示圖表 具體實現
- 網頁模板:關于jsp頁面使用jstl的異常分析
- JSP頁面中文傳遞參數使用escape編碼
- 基于jsp:included的使用與jsp:param亂碼的解決方法
- Java Web項目中連接Access數據庫的配置方法
- JDBC連接Access數據庫的幾種方式介紹
- 網站圖片路徑的問題:絕對路徑/虛擬路徑
- (jsp/html)網頁上嵌入播放器(常用播放器代碼整理)
- jsp下顯示中文文件名及絕對路徑下的圖片解決方法
- 相關鏈接:
- 教程說明:
JSP教程-JSP教程之整合hibernate持久層1(2)。