posts - 12, comments - 6, trackbacks - 0, articles - 0
            BlogJava :: 首頁 :: 新隨筆 :: 聯系 :: 聚合  :: 管理

          Struts學習筆記(2)----靈活的配置

          Posted on 2007-10-28 16:42 oahiq.Max 閱讀(360) 評論(0)  編輯  收藏 所屬分類: Java
              關于Struts的配置,我認為對于一個初學者來說真是太煩瑣、太復雜了。要一次性記住那所有的element和property都是什么意思,什么時候需要使用真是out of my ability。我想在這里就把模板記下,再把一些主要的配置記下來吧。

          1、關于web.xml
              下面列出一個完整的xml配置示例。
             
           1 <?xml version="1.0" encoding="UTF-8"?>
           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 <web-app>
           6 <servlet>
           7 <servlet-name>storefront</servlet-name>
           8 <servlet-class>org.apache.struts.action.ActionServlet</servlet-class>
           9 <init-param>
          10 <param-name>config</param-name>
          11 <param-value>/WEB-INF/struts-config.xml</param-value>
          12 </init-param>
          13 <init-param>
          14 <param-name>debug</param-name>
          15 <param-value>3</param-value>
          16 </init-param>
          17 <init-param>
          18 <param-name>detail</param-name>
          19 <param-value>3</param-value>
          20 </init-param>
          21 <init-param>
          22 <param-name>validating</param-name>
          23 <param-value>true</param-value>
          24 </init-param>
          25 <load-on-startup>1</load-on-startup>
          26 </servlet>
          27 <servlet-mapping>
          28 <servlet-name>storefront</servlet-name>
          29 <url-pattern>/action/*</url-pattern>
          30 </servlet-mapping>
          31 <welcome-file-list>
          32 <welcome-file>index.jsp</welcome-file>
          33 </welcome-file-list>
          34 <error-page>
          35 <error-code>404</error-code>
          36 <location>/common/404.jsp</location>
          37 </error-page>
          38 <error-page>
          39 <error-code>500</error-code>
          40 <location>/common/500.jsp</location>
          41 </error-page>
          42 <taglib>
          43 <taglib-uri>/WEB-INF/struts-html.tld</taglib-uri>
          44 <taglib-location>/WEB-INF/struts-html.tld</taglib-location>
          45 </taglib>
          46 <taglib>
          47 <taglib-uri>/WEB-INF/struts-bean.tld</taglib-uri>
          48 <taglib-location>/WEB-INF/struts-bean.tld</taglib-location>
          49 </taglib>
          50 <taglib>
          51 <taglib-uri>/WEB-INF/struts-logic.tld</taglib-uri>
          52 <taglib-location>/WEB-INF/struts-logic.tld</taglib-location>
          53 </taglib>
          54 <taglib>
          55 <taglib-uri>/WEB-INF/struts-template.tld</taglib-uri>
          56 <taglib-location>/WEB-INF/struts-template.tld</taglib-location>
          57 </taglib>
          58 </web-app>
              2、Struts Configuration File
                 同樣貼一個模板先。
            1 <?xml version="1.0" encoding="UTF-8" ?>
            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 <struts-config>
            6 <!--
            7 <data-sources>
            8 <data-source>
            9 <set-property property="autoCommit" value="true"/>
           10 <set-property property="description" value="Resin Data Source"/>
           11 <set-property property="driverClass" value="com.caucho.jdbc.mysql.Driver"/>
           12 <set-property property="maxCount" value="10"/>
           13 <set-property property="minCount" value="2"/>
           14 <set-property property="user" value="admin"/>
           15 <set-property property="password" value="admin"/>
           16 <set-property property="url" value="jdbc:mysqlcaucho://
           17 localhost:3306/storefront"/>
           18 </data-source>
           19 </data-sources>
           20 -->
           21 <form-beans>
           22 <form-bean
           23 name="loginForm"
           24 type="com.oreilly.struts.storefront.security.LoginForm"/>
           25 <form-bean
           26 name="itemDetailForm"
           27 dynamic="true"
           28 type="org.apache.struts.action.DynaActionForm">
           29 <form-property name="view" type="com.oreilly.struts.catalog.view.ItemView"/>
           30 </form-bean>
           31 </form-beans>
           32 <global-exceptions>
           33 <exception
           34 key="global.error.invalidlogin"
           35 path="/security/signin.jsp"
           36 scope="request"
           37 type="com.oreilly.struts.framework.exceptions.InvalidLoginException"/>
           38 </global-exceptions>
           39 <global-forwards>
           40 <forward name="Login" path="/security/signin.jsp" redirect="true"/>
           41 <forward name="SystemFailure" path="/common/systemerror.jsp"/>
           42 <forward
           43 name="SessionTimeOut"
           44 path="/common/sessiontimeout.jsp"
           45 redirect="true"/>
           46 </global-forwards>
           47 <action-mappings>
           48 <action
           49 path="/viewsignin"
           50 parameter="/security/signin.jsp"
           51 type="org.apache.struts.actions.ForwardAction"
           52 scope="request"
           53 name="loginForm"
           54 validate="false"
           55 input="/index.jsp">
           56 </action>
           57 <action
           58 path="/signin"
           59 type="com.oreilly.struts.storefront.security.LoginAction"
           60 scope="request"
           61 name="loginForm"
           62 validate="true"
           63 input="/security/signin.jsp">
           64 <forward name="Success" path="/index.jsp" redirect="true"/>
           65 <forward name="Failure" path="/security/signin.jsp" redirect="true"/>
           66 </action>
           67 <action
           68 path="/signoff"
           69 type="com.oreilly.struts.storefront.security.LogoutAction"
           70 scope="request"
           71 validate="false"
           72 input="/security/signin.jsp">
           73 <forward name="Success" path="/index.jsp" redirect="true"/>
           74 </action>
           75 <action
           76 path="/home"
           77 parameter="/index.jsp"
           78 type="org.apache.struts.actions.ForwardAction"
           79 scope="request"
           80 validate="false">
           81 </action>
           82 <action
           83 path="/viewcart"
           84 parameter="/order/shoppingcart.jsp"
           85 type="org.apache.struts.actions.ForwardAction"
           86 scope="request"
           87 validate="false">
           88 </action>
           89 <action path="/cart"
           90 type="com.oreilly.struts.storefront.order.ShoppingCartActions"
           91 scope="request"
           92 input="/order/shoppingcart.jsp"
           93 validate="false"
           94 parameter="method">
           95 <forward name="Success" path="/action/viewcart" redirect="true"/>
           96 </action>
           97 <action
           98 path="/viewitemdetail"
           99 name="itemDetailForm"
          100 input="/index.jsp"
          101 type="com.oreilly.struts.storefront.catalog.GetItemDetailAction"
          102 scope="request"
          103 validate="false">
          104 <forward name="Success" path="/catalog/itemdetail.jsp"/>
          105 </action>
          106 <action
          107 path="/begincheckout"
          108 input="/order/shoppingcart.jsp"
          109 type="com.oreilly.struts.storefront.order.CheckoutAction"
          110 scope="request"
          111 validate="false">
          112 <forward name="Success" path="/order/checkout.jsp"/>
          113 </action>
          114 <action
          115 path="/getorderhistory"
          116 input="/order/orderhistory.jsp"
          117 type="com.oreilly.struts.storefront.order.GetOrderHistoryAction"
          118 scope="request"
          119 validate="false">
          120 <forward name="Success" path="/order/orderhistory.jsp"/>
          121 </action>
          122 </action-mappings>
          123 <controller
          124 contentType="text/html;charset=UTF-8"
          125 debug="3"
          126 locale="true"
          127 nocache="true"
          128 processorClass="com.oreilly.struts.framework.CustomRequestProcessor"/>
          129 <message-resources
          130 parameter="StorefrontMessageResources"
          131 null="false"/>
          132 <message-resources
          133 key="IMAGE_RESOURCE_KEY"
          134 parameter="StorefrontImageResources"
          135 null="false"/>
          136 </struts-config>
                確實是想不到還要寫點什么,關于這個配置我想還是抄抄模板,寫的時候看看文檔好了^_^。
          主站蜘蛛池模板: 济源市| 行唐县| 津市市| 武功县| 四川省| 绵竹市| 灵寿县| 郑州市| 武陟县| 平顶山市| 玛沁县| 克拉玛依市| 文登市| 通许县| 武城县| 新营市| 嘉禾县| 曲沃县| 美姑县| 卢湾区| 丘北县| 横峰县| 尼玛县| 吉安县| 重庆市| 沙河市| 遵化市| 舟山市| 新昌县| 射阳县| 龙口市| 吉水县| 鄢陵县| 泰和县| 瓦房店市| 永丰县| 句容市| 葵青区| 桃江县| 滕州市| 舒兰市|