Posted on 2007-10-28 16:42
oahiq.Max 阅读(351)
评论(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>
确实是想不到还要写点什么,关于这个配置我想还是抄抄模板,写的时候看看文档好了^_^。