struts+spring+hibernate的web應用(4.3)

接着編寫配置文件。
在 struts-config 包中新建 struts-config.xml 。代碼如下:
  
  1. <? xml version="1.0" encoding="ISO-8859-1" ?>    
  2.  <! DOCTYPE struts-config PUBLIC   
  3.     "-//Apache Software Foundation//DTD Struts Configuration 1.1//EN"   
  4.     "http://jakarta.apache.org/struts/dtds/struts-config_1_1.dtd" >    
  5.     
  6.  < struts-config >    
  7.      < form-beans >    
  8.          < form-bean  name ="productsForm"  type ="com.game.products.web.forms.ProductsForm"   />    
  9.      </ form-beans >    
  10.        
  11.      < global-forwards >    
  12.          < forward  name ="success"  path ="/products/product_success.jsp"   />    
  13.          < forward  name ="failure"  path ="/products/product_failure.jsp"   />    
  14.      </ global-forwards >    
  15.        
  16.      < action-mappings >    
  17.          < action  path ="/getProducts"  type ="org.springframework.web.struts.DelegatingActionProxy"  parameter ="method"  scope ="request"  validate ="false" >    
  18.              < forward  name ="all"  path ="/products/products.jsp"   />    
  19.          </ action >    
  20.          < action  path ="/getProduct"  type ="org.springframework.web.struts.DelegatingActionProxy"  parameter ="method"  scope ="request"  validate ="false" >    
  21.              < forward  name ="one"  path ="/products/product.jsp"   />    
  22.          </ action >    
  23.          < action  path ="/deleteProduct"  type ="org.springframework.web.struts.DelegatingActionProxy"  parameter ="method"  scope ="request"  validate ="false" >                
  24.          </ action >    
  25.          < action  path ="/addProductPage"  type ="org.springframework.web.struts.DelegatingActionProxy"  parameter ="method"  scope ="request"  validate ="false" >    
  26.              < forward  name ="add"  path ="/products/addproduct.jsp"   />    
  27.          </ action >    
  28.          < action  path ="/addProduct"  name ="productsForm"  type ="org.springframework.web.struts.DelegatingActionProxy"  parameter ="method"  scope ="request"  validate ="false"  input ="/product_failure.jsp" >    
  29.          </ action >    
  30.          < action  path ="/updateProduct"  name ="productsForm"  type ="org.springframework.web.struts.DelegatingActionProxy"  parameter ="method"  scope ="request"  validate ="false"  input ="/product_failure.jsp" >    
  31.          </ action >    
  32.            
  33.          < action  path ="/returnProduct"  type ="org.springframework.web.struts.DelegatingActionProxy"  parameter ="method"  scope ="request"  validate ="false" >    
  34.              < forward  name ="all"  path ="/products/products.jsp"   />    
  35.          </ action >    
  36.          < action  path ="/queryProducts"  type ="org.springframework.web.struts.DelegatingActionProxy"  parameter ="method"  scope ="request"  validate ="false" >    
  37.              < forward  name ="all"  path ="/products/products.jsp"   />    
  38.          </ action >    
  39.      </ action-mappings >    
  40.        
  41.      < message-resources  parameter ="com.game.resources.ApplicationResourcesProducts"   />    
  42.        
  43.      < plug-in  className ="org.apache.struts.validator.ValidatorPlugIn" >    
  44.          < set-property  property ="pathnames"    
  45.             value ="/WEB-INF/struts-validator/validator-rules.xml,/WEB-INF/struts-validator/validation.xml" />    
  46.      </ plug-in >        
  47.        
  48.  </ struts-config >  
需要注意的是,這裏的 action 交由 spring 的 DelegatingActionProxy 管理了。
打開 applicationContext.xml ,接着添加如下代碼:
  1. < bean  name ="/getProducts"  class ="com.game.products.web.actions.ProductsAction"  singleton ="false" >    
  2.     < property  name ="productsService" >    
  3.         < ref  bean ="productsService" />    
  4.     </ property >    
  5.     < property  name ="pagerService" >    
  6.         < ref  bean ="pagerService" />    
  7.     </ property >    
  8. </ bean >    
  9. < bean  name ="/getProduct"  class ="com.game.products.web.actions.ProductsAction"  singleton ="false" >    
  10.     < property  name ="productsService" >    
  11.         < ref  bean ="productsService" />    
  12.     </ property >    
  13. </ bean >    
  14. < bean  name ="/deleteProduct"  class ="com.game.products.web.actions.ProductsAction"  singleton ="false" >    
  15.     < property  name ="productsService" >    
  16.         < ref  bean ="productsService" />    
  17.     </ property >    
  18. </ bean >    
  19. < bean  name ="/addProductPage"  class ="com.game.products.web.actions.ProductsAction"  singleton ="false" >    
  20.     < property  name ="productsService" >    
  21.         < ref  bean ="productsService" />    
  22.     </ property >    
  23. </ bean >    
  24. < bean  name ="/addProduct"  class ="com.game.products.web.actions.ProductsAction"  singleton ="false" >    
  25.     < property  name ="productsService" >    
  26.         < ref  bean ="productsService" />    
  27.     </ property >    
  28. </ bean >    
  29. < bean  name ="/updateProduct"  class ="com.game.products.web.actions.ProductsAction"  singleton ="false" >    
  30.     < property  name ="productsService" >    
  31.         < ref  bean ="productsService" />    
  32.     </ property >    
  33. </ bean >    
  34. < bean  name ="/returnProduct"  class ="com.game.products.web.actions.ProductsAction"  singleton ="false" >    
  35.     < property  name ="productsService" >    
  36.         < ref  bean ="productsService" />    
  37.     </ property >    
  38.     < property  name ="pagerService" >    
  39.         < ref  bean ="pagerService" />    
  40.     </ property >    
  41. </ bean >    
  42. < bean  name ="/queryProducts"  class ="com.game.products.web.actions.ProductsAction"  singleton ="false" >    
  43.     < property  name ="productsService" >    
  44.         < ref  bean ="productsService" />    
  45.     </ property >    
  46.     < property  name ="pagerService" >    
  47.         < ref  bean ="pagerService" />    
  48.     </ property >    
  49. </ bean >  

接着編寫 web.xml ,代碼如下:
  1. <? xml version="1.0" encoding="GB2312" ?>    
  2.  <! DOCTYPE web-app   
  3.     PUBLIC "-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN"   
  4.     "http://java.sun.com/dtd/web-app_2_3.dtd" >    
  5.     
  6.  < web-app >    
  7.      < display-name > 遊戲軟件管理系統 </ display-name >    
  8.      < context-param >    
  9.          < param-name > log4jConfigLocation </ param-name >    
  10.          < param-value > /WEB-INF/classes/log4j.properties </ param-value >    
  11.      </ context-param >    
  12.      < context-param >    
  13.          < param-name > contextConfigLocation </ param-name >    
  14.          < param-value > /WEB-INF/spring-context/applicationContext.xml </ param-value >    
  15.       </ context-param >    
  16.        
  17.      < filter >    
  18.          < filter-name > Set Character Encoding </ filter-name >    
  19.          < filter-class > com.game.commons.SetCharacterEncodingFilter </ filter-class >    
  20.          < init-param >    
  21.              < param-name > encoding </ param-name >    
  22.              < param-value > GB2312 </ param-value >    
  23.          </ init-param >    
  24.      </ filter >    
  25.     
  26.      < filter-mapping >    
  27.          < filter-name > Set Character Encoding </ filter-name >    
  28.          < url-pattern > /* </ url-pattern >    
  29.      </ filter-mapping >    
  30.     
  31.      <listener>          
  32.           <listener-class>org.springframework.web.context.ContextLoaderListener </listener-class>          
  33.      </listener>          
  34.      <listener>          
  35.          <listener-class>org.springframework.web.util.Log4jConfigListener </listener-class>          
  36.      </listener>          
  37.   
  38.     < servlet >    
  39.          < servlet-name > action </ servlet-name >    
  40.          < servlet-class > org.apache.struts.action.ActionServlet </ servlet-class >    
  41.              < init-param >    
  42.                < param-name > config </ param-name >    
  43.                < param-value > /WEB-INF/struts-config/struts-config.xml </ param-value >    
  44.              </ init-param >    
  45.              < init-param >    
  46.                  < param-name > debug </ param-name >    
  47.                  < param-value > 3 </ param-value >    
  48.              </ init-param >    
  49.              < init-param >    
  50.                  < param-name > detail </ param-name >    
  51.                  < param-value > 3 </ param-value >    
  52.              </ init-param >    
  53.              < init-param >    
  54.                  < param-name > nocache </ param-name >    
  55.                  < param-value > yes </ param-value >    
  56.              </ init-param >    
  57.              < load-on-startup > 2 </ load-on-startup >    
  58.      </ servlet >    
  59.        
  60.      < servlet-mapping >    
  61.          < servlet-name > action </ servlet-name >    
  62.          < url-pattern > *.do </ url-pattern >    
  63.      </ servlet-mapping >    
  64.     
  65.      < welcome-file-list >    
  66.          < welcome-file > products/index.jsp </ welcome-file >    
  67.      </ welcome-file-list >    
  68.     
  69.      < taglib >    
  70.          < taglib-uri > struts-bean </ taglib-uri >    
  71.          < taglib-location > /WEB-INF/tld/struts-bean.tld </ taglib-location >    
  72.      </ taglib >  
  73.      < taglib >    
  74.          < taglib-uri > struts-html </ taglib-uri >    
  75.          < taglib-location > /WEB-INF/tld/struts-html.tld </ taglib-location >    
  76.      </ taglib >  
  77.      < taglib >    
  78.          < taglib-uri > struts-logic </ taglib-uri >    
  79.          < taglib-location > /WEB-INF/tld/struts-logic.tld </ taglib-location >    
  80.      </ taglib >  
  81.      < taglib >    
  82.          < taglib-uri > struts-nested </ taglib-uri >    
  83.          < taglib-location > /WEB-INF/tld/struts-nested.tld </ taglib-location >    
  84.      </ taglib >    
  85.  </ web-app >&nb
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章