<!--
Struts2 Chapter2 struts.xml
Goal: struts ! ,
, ,
, , ...!
-->
, struts.xml , struts2 :
Struts2 :
--- > ----> filterdispatcher ------> ActionProxy( , struts.xml )---->ActionInvocation(action , Action; )——> Action , 。
, struts.xml :
<struts>
//extends ,namespace (reminds me C#),"/" WebRoot
<package name="myPackage( , )" extends="struts-default" namespace="/">
<action name="DoingMyAction( )" class="com.shu.action.DoIt( )" method="makeIt( , , )">
<result name=" "> </result>
</action>
</package>
</struts>
,
Struts2 , , action , ,
, ! , action !
a) :
<action name=" " class=" ">
<result name="xx">xx</result>
</action>
: action method, : ! .action( action )
, action, !
eg:
//
<a href="myAction!doSomething.action">click here</a>
//struts.xml
<action name="myAction" class="com.shu.action.DoIt"></action>
// , click , com.shu.action.DoIt doSomething()
b) :
<action name="*Action" class=" " method="{1}"></action>
:name * , Action action
class ,method {1}, {1}( 1 ) * , * !
eg:
// :
<a href="doSomethingAction.action">click me</a>
//action
<action name="*Action" class="com.shu.action.DoIt" method=""{1}></action>
// click me action doSomething
// *, , !
<action name="*Action" class="com.shu.action.DoIt" method=""{1}>
<result name="success">{1}.jsp</result>
</action>
,
a) :
, : !
:requestScope,
: requestScope, !
result , type , : ,
eg:<result name="success">index.jsp</result>
, type
eg:<result name="success" type="redirect">index.jsp</result>
redirect: ~javaWeb !
b) action , result ,
:
<result name=" " type="redirectAction">
<param name="actionName"> action </param>
<param name="namespace"> </param>
</result>
c) ( ), JQuery html(),JS innerHTML;
<result name=" " type="plainText">
<param name="location">index.jsp</param>
<param name="charSet">utf-8</param>
</result>
index.jsp index.jsp , !
, :
, , ,
success failed, result , ,
<global-results>
<result name=" "> </result>
<result name=" "> </result>
</global-results>
eg:
<global-results>
<result name="success">success.jsp</result>
<result name="failed">failed.jsp</result>
</global-results>
: , <global-results></global-results> <action> , action !
, !
<global-exception-mappings>
<exception-mapping result=" " exception=" "></exception-mapping>
</global-exception-mappings>
eg:
<global-exception-mappings>
<exception-mapping result="error" exception="java.lang.exception"></exception-mapping>
</global-exception-mappings>
: :
1) :<%@ taglib uri="/struts-tags" prefix="s" %>
2) :<s:property value="exceptionStack"/>
,
, ~
<constant name="" value=""></constant>
<!-- : ( ) -->
<!-- :struts.custome.i18n.resources( ) -->
<!-- :struts.i18n.encoding( , utf-8 ) -->
, !
struts , MiniStruts , !!
: , , ,
~ , , , action class
: ! method , ,
! ~
<!--
Author:Lovingshu's Forever
Date:2011-10-25 20:36
Remark: 3 , 3 , : ,
+PJ , ~ ~ ~ ~
!
-->