锘??xml version="1.0" encoding="utf-8" standalone="yes"?>
Struts鐨勫畼鏂圭綉绔欎笂鍏跺疄鏈夌ず渚?鍙涓嬭澆1.2.6浠ヤ笂鐨勫紑鍙戝寘.
鍏跺疄1.1涔熸敮鎸佸閰嶇疆鏂囦歡,涓嶈繃瀹炵幇鍥伴毦,鎴戜篃娌℃湁璇?
娉ㄦ剰:鎴戣繖閲岀敤鐨勬槸Struts 1.2.
涓嬮潰寮濮嬪惂:
鍏堣鏄庝竴涓?宸ョ▼鍚嶄負Module,鍒嗕笁涓瓙妯″潡,鍒嗗埆鏄痬odule1,module2,module3,涓轟簡綆鍗曡搗瑙佹瘡涓涓ā鍧椾笅闈㈠彧鏀句簡涓涓惈鏈夐摼鎺ュ埌鍏跺畠妯″潡鐨凧SP鏂囦歡(index.jsp),.鐩綍緇撴瀯濡備笅:
浠ヤ笅鏄悇涓枃浠剁殑浠g爜:
Module\WebRoot\index.jsp:
<%@ page language="java" pageEncoding="GB2312"%>
<%@ taglib uri="http://jakarta.apache.org/struts/tags-bean" prefix="bean"%>
<%@ taglib uri="http://jakarta.apache.org/struts/tags-html" prefix="html"%>
<%@ taglib uri="http://jakarta.apache.org/struts/tags-logic" prefix="logic"%>
<%@ taglib uri="http://jakarta.apache.org/struts/tags-nested" prefix="nested"%>
<logic:redirect forward="welcome"/>
娌′粈涔堝唴瀹?灝辨槸鐩存帴閲嶅畾鍚戝埌welcome,鍦ㄨ繖閲孲truts浼氭煡鎵網ebRoot\WEB-INF\struts-config.xml涓嬬殑<global-forwards>鍏冪礌閲?鐪嬬湅鏄惁鏈?lt;forward name="welcome" path="/Welcome.do" />榪欐牱鍚嶅瓧鐨勮漿鍚?
Module/WebRoot/WEB-INF/struts-config.xml:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE struts-config PUBLIC "-//Apache Software Foundation//DTD Struts Configuration 1.2//EN" "http://struts.apache.org/dtds/struts-config_1_2.dtd">
<struts-config>
<data-sources />
<form-beans />
<global-exceptions />
<global-forwards>
聽<forward name="welcome" path="/Welcome.do" />
</global-forwards>
<action-mappings>
聽<action path="/Welcome" forward="/Welcome.jsp" />
聽<action path="/toModule" type="org.apache.struts.actions.SwitchAction" />
</action-mappings>
<message-resources parameter="com.utopian.struts.ApplicationResources" />
</struts-config>
鍥犱負鏈?lt;forward name="welcome" path="/Welcome.do" />,鎵浠ュ畠灝變細杞悜鍒?Welcome.do,鐒跺悗Struts鍙堜細鍘繪煡鎵懼埌Web.xml閲屽叧浜?do鐨勫鐞?
Module\WebRoot\WEB-INF\web.xml:
<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns="http://java.sun.com/xml/ns/j2ee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" version="2.4" xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee聽聽 http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd">
聽<display-name>Module Test</display-name>
聽<servlet>
聽聽<servlet-name>action</servlet-name>
聽聽<servlet-class>org.apache.struts.action.ActionServlet</servlet-class>
聽聽<init-param>
聽聽聽<param-name>config</param-name>
聽聽聽<param-value>/WEB-INF/struts-config.xml</param-value>
聽聽</init-param>
聽聽<!-- module configurations -->
聽聽<init-param>
聽聽聽<param-name>config/module1</param-name>
聽聽聽<param-value>/WEB-INF/module1/struts-config.xml</param-value>
聽聽</init-param>
聽聽<init-param>
聽聽聽<param-name>config/module2</param-name>
聽聽聽<param-value>/WEB-INF/module2/struts-config.xml</param-value>
聽聽</init-param>
聽聽<init-param>
聽聽聽<param-name>config/module3</param-name>
聽聽聽<param-value>/WEB-INF/module3/struts-config.xml</param-value>
聽聽</init-param>
聽聽<init-param>
聽聽聽<param-name>debug</param-name>
聽聽聽<param-value>3</param-value>
聽聽</init-param>
聽聽<init-param>
聽聽聽<param-name>detail</param-name>
聽聽聽<param-value>3</param-value>
聽聽</init-param>
聽聽<load-on-startup>0</load-on-startup>
聽</servlet>
聽<servlet-mapping>
聽聽<servlet-name>action</servlet-name>
聽聽<url-pattern>*.do</url-pattern>
聽</servlet-mapping>
聽<!-- The Usual Welcome File List -->
聽<welcome-file-list>
聽聽<welcome-file>index.jsp</welcome-file>
聽</welcome-file-list>
</web-app>
娉ㄦ剰榪欓噷,聽<servlet-name>action</servlet-name>聽<url-pattern>*.do</url-pattern>,鏍規嵁榪欎釜,Struts浼氭壘鍒癮ction.鐒跺悗鍘籹truts-config.xml鏌ユ壘鎵鍖歸厤鐨勫?鍥犱負鏈?lt;action path="/Welcome" forward="/Welcome.jsp" />,/Weclcome.do灝變細鐩存帴杞埌/Welcome.jsp.
Module\WebRoot\Welcome.jsp:
榪欎釜鏂囦歡灝辨槸涓浜涜漿鍚?
聽<ul>
聽聽聽聽聽 <li><html:link module="/module1" action="/module1">榪欐槸絎竴涓瓙妯″潡module1鐨勯摼鎺?lt;/html:link></li>
聽聽聽聽聽 <li><html:link module="/module2" action="/module2">榪欐槸絎簩涓瓙妯″潡module2鐨勯摼鎺?lt;/html:link></li>
聽聽聽聽聽 <li><html:link module="/module3" action="/module3">榪欐槸絎笁涓瓙妯″潡module3鐨勯摼鎺?lt;/html:link></li>
聽 </ul>
鍦⊿truts 1.2閲?濡傛灉鍦╨ink鏍囩閲岀敤浜唌odule灞炴?灝辮〃紺烘槸妯″潡闂磋漿鍙?鎵浠ュ氨浼氬厛鍒皐eb.xml鍘婚噷鏌ユ壘鍏充簬妯″潡鐨勫畾涔?姣斿璇磋繖涓犅犅?lt;param-name>config/module1</param-name><param-value>/WEB-INF/module1/struts-config.xml</param-value>,config鏄〃紺洪粯璁ょ殑妯″潡,鑰宑onfig/鍒欒〃紺哄瓙妯″潡,榪欎釜鏂囦歡澶瑰疄闄呬笂涓嶅瓨鍦?鎺ユ潵鐨勬儏鍐電被浼煎墠闈㈣鐨勬煡鎵捐漿鍚戠殑榪囩▼.
榪樻湁浠涔堜笉娓呮鐨勫湴鏂?璇瘋仈緋繪垜,鎴戜細灝芥垜鎵鑳藉府鍔╀綘!
涓嬮潰鏈夊畬鏁寸殑欏圭洰涓嬭澆:
Struts 1.2澶氭ā鍧楀紑鍙戠畝鍗曠ず渚?/a>