Struts-config 常用配置

  1. <?xml version="1.0" encoding="ISO-8859-1" ?>
  2. <!DOCTYPE struts-config PUBLIC
  3.           "-//Apache Software Foundation//DTD Struts Configuration 1.2//EN"
  4.           "http://jakarta.apache.org/struts/dtds/struts-config_1_2.dtd">
  5. <struts-config>
  6. <!-- ==================== Data Source Configuration ========================-->
  7. <data-sources>
  8.   <!-- default datasource -->
  9.   <data-source type="org.apache.commons.dbcp.BasicDataSource">
  10.      <set-property  property="driverClassName" value="com.microsoft.jdbc.sqlserver.SQLServerDriver" />
  11.      <set-property  property="url"  value="jdbc:microsoft:sqlserver://127.0.0.1:1433;DatabaseName=northwind" />
  12.      <set-property  property="username"  value="sa" />
  13.      <set-property  property="password"  value="" />
  14.      <set-property  property="maxIdle"   value="30" />
  15.      <set-property  property="maxActive" value="100" />
  16.      <set-property  property="maxWait"   value="10000" />
  17.   </data-source>
  18.   
  19.   <!-- non-default datasource -->
  20.   <data-source key="ds1" type="org.apache.commons.dbcp.BasicDataSource">
  21.      <set-property  property="driverClassName" value="com.microsoft.jdbc.sqlserver.SQLServerDriver" />
  22.      <set-property  property="url"  value="jdbc:microsoft:sqlserver://127.0.0.1:1433;DatabaseName=northwind" />
  23.      <set-property  property="username"  value="sa" />
  24.      <set-property  property="password"  value="" />
  25.      <set-property  property="maxIdle"   value="30" />
  26.      <set-property  property="maxActive" value="100" />
  27.      <set-property  property="maxWait"   value="10000" />
  28.   </data-source>
  29.   ...
  30. </data-sources>
  31. <!-- ===================== Form Bean Definitions ===========================-->
  32. <form-beans>
  33.   <!-- extends org.apache.struts.action.ActionForm -->
  34.   <form-bean name="inputForm" type="app.InputForm"/>
  35.   <!-- Custom FormBeanConfig -->
  36.   <form-bean className="app.MyFormBeanConfig"
  37.              name="inputForm"
  38.              type="app.InputForm"/>
  39.   <!-- dynamic form-bean (extends org.apache.struts.action.DynaActionForm) -->
  40.   <form-bean name="logonForm"
  41.              type="org.apache.struts.action.DynaActionForm">
  42.      <form-property  name="username"  type="java.lang.String"/>
  43.      <form-property  name="password"  type="java.lang.String"/>
  44.      <form-property  name="district"  type="java.lang.String" initial="Heping"/>
  45.      <form-property  name="telephone" type="java.lang.String[]" size="2"/>
  46.   </form-bean>
  47.   ...
  48. </form-beans>
  49. <!-- ====================== Global Exception Definitions ================== -->
  50. <global-exceptions>
  51.    <exception  key="expired.password"
  52.                type="app.ExpiredPasswordException"
  53.                path="/changePassword.jsp"/>
  54.                
  55.    <!-- bundle -->
  56.    <exception  bundle="msgrsc1"
  57.                key="exception.thrown"
  58.                type="java.lang.Exception"
  59.                scope="session"/>
  60.                
  61.    <!-- handler -->
  62.    <exception  handler="app.MyExceptionHandler"
  63.                key="exception.thrown"
  64.                type="java.lang.Exception"/>
  65.     ...
  66. </global-exceptions>
  67. <!-- ====================== Global Forward Definitions ==================== -->
  68. <global-forwards>
  69.    <forward  name="login"  path="/login.jsp" />
  70.    <!-- forward to an action -->
  71.    <forward  name="welcome"  path="/welcome.do" />
  72.    <!-- redirect -->
  73.    <forward  name="test"  path="/test.jsp"  redirect="true"/>
  74.    <!-- contextRelative -->
  75.    <forward  name="process"  path="/process.jsp" contextRelative="true"/>
  76.    <!-- module -->
  77.    <forward  name="success"  path="/success.jsp" module="/moduleA"/>
  78.    <forward  name="success"  path="/success.jsp" module="/"/>
  79.    ...
  80. </global-forwards>
  81. <!-- ====================== Action Mapping Definitions ==================== -->
  82. <action-mappings>
  83.    <!-- forward or ForwardAction -->
  84.    <action  path="/welcome1" forward="/pages/welcome1.jsp"/>   
  85.    <action  path="/input1"
  86.             type="org.apache.struts.actions.ForwardAction"
  87.             parameter="/pages/input1.jsp"/>
  88.    <!-- include or IncludeAction -->
  89.    <action  path="/welcome2" include="/pages/welcome2.jsp"/>   
  90.    <action  path="/input2"
  91.             type="org.apache.struts.actions.IncludeAction"
  92.             parameter="/pages/input2.jsp"/>
  93.    
  94.    <!-- type -->
  95.    <action  path="/InputSubmit1"
  96.             type="app.MyInputAction"
  97.             name="inputForm"
  98.             scope="request"
  99.             validate="true"
  100.             input="/pages/input.jsp"/>
  101.    <!-- attribute -->
  102.    <action  attribute="inputA"
  103.             path="/InputSubmit2"
  104.             type="app.MyInputAction"
  105.             name="inputForm"
  106.             validate="true"
  107.             input="/pages/input.jsp"/>
  108.    <!-- unknown -->
  109.    <action  path="/InputSubmit3"
  110.             type="app.MyInputAction"
  111.             name="inputForm"
  112.             scope="request"
  113.             unknown="true"
  114.             validate="true"
  115.             input="/pages/input.jsp"/>
  116.    <!-- wildcard -->
  117.    <action  path="/edit*"
  118.             type="app.Edit{1}Action"
  119.             name="inputForm"
  120.             scope="request"
  121.             validate="true"
  122.             input="/pages/edit{1}.jsp"/>
  123.    <!-- local forward and exception -->
  124.    <action  path="/InputSubmit1"
  125.             type="app.MyInputAction"
  126.             name="inputForm"
  127.             scope="request"
  128.             validate="true"
  129.             input="/pages/input.jsp">
  130.       <forward name="success" path="/success.jsp"/>
  131.       <forward name="failure" path="/failure.jsp"/>
  132.       <exception  key="expired.password"
  133.                   type="app.ExpiredPasswordException"
  134.                   path="/changePassword.jsp"/>
  135.    </action>
  136.    ...
  137. </action-mappings>
  138. <!-- ======================= Controller Configuration ===================== -->
  139. <controller processorClass="org.apache.struts.tiles.TilesRequestProcessor"/>
  140. <!--
  141. <== inputForward ==>
  142. <controller inputForward="true" />
  143.   or
  144. <== locale ==>
  145. <controller locale="false" />
  146. -->
  147. <!-- ====================== Message Resources Definitions ================= -->
  148. <!-- default message-resources -->
  149. <message-resources parameter="app.resource.MyResources" />
  150. <!-- non-default message-resources -->
  151. <message-resources key="msgrsc1" parameter="app.resource.MyResources" />
  152. <!-- null -->
  153. <message-resources key="msgrsc1" parameter="app.resource.MyResources" null="false" />
  154. <!-- ====================== Plug Ins Configuration ======================== -->
  155. <!-- **************************** Validator plugin ************************ -->
  156. <plug-in className="org.apache.struts.validator.ValidatorPlugIn">
  157.   <set-property property="pathnames" value="/WEB-INF/validator-rules.xml, /WEB-INF/validation.xml"/>
  158. </plug-in>
  159. <!-- ************************* Tiles plugin ******************************* -->
  160. <!-- This plugin initialize Tiles definition factory. This later can takes some
  161.      parameters explained here after. The plugin first read parameters from
  162.      web.xml, thenoverload them with parameters defined here. All parameters
  163.      are optional.
  164.      The plugin should be declared in each struts-config file.
  165.        - definitions-config: (optional)
  166.             Specify configuration file names. There can be several comma
  167.             separated file names (default: ?? )
  168.        - moduleAware: (optional - struts1.1)
  169.             Specify if the Tiles definition factory is module aware. If true
  170.             (default), there will be one factory for each Struts module.
  171.             If false, there will be one common factory for all module. In this
  172.             later case, it is still needed to declare one plugin per module.
  173.             The factory will be initialized with parameters found in the first
  174.             initialized plugin (generally the one associated with the default
  175.             module).
  176.               true : One factory per module. (default)
  177.               false : one single shared factory for all modules
  178.        - definitions-parser-validate: (optional)
  179.             Specify if xml parser should validate the Tiles configuration file.
  180.               true : validate. DTD should be specified in file header (default)
  181.               false : no validation
  182.       Paths found in Tiles definitions are relative to the main context.
  183. -->
  184. <plug-in className="org.apache.struts.tiles.TilesPlugin" >
  185.    <!-- Path to XML definition file -->
  186.    <set-property property="definitions-config" value="/WEB-INF/tiles-defs.xml" />
  187.    <!-- Set Module-awareness to true -->
  188.    <set-property property="moduleAware" value="true" />
  189.    <set-property property="definitions-parser-validate" value="true" />
  190. </plug-in>
  191. </struts-config>
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值