Struts 2.0(i18n)http://www.blogjava.net/max/category/16130.html
Web
Struts 1.xFILE-NAME_xx_XX.propertiesFILE-NAMEstruts-config.xml<bean:message>
“”Struts2.0
HelloWorld
——HelloWorldHelloWorld
1. Eclipse Struts 2.0 2. srcstruts.properties
struts.custom.i18n.resources=globalMessages
Struts2.0struts.xmlstruts.propertiesWEB-INF/classes/struts.xmlstruts.propertiesStruts 2.0Runtime
3. srcglobalMessages_en_US.propertiesHelloWorld=HelloWorld!
4. srcglobalMessages_zh_CN.propertiesHelloWorld=
propertiesEclipsepluginUnicodenative2asciiEclipseSoftware Update
1EclipseHelpSoftware UpdateFindandInstall2Install/UpdateSearch fornewfeaturestoinstallNext3InstallNewRemote Site4NewUpdate SiteName“PropEdit”URLhttp://propedit.sourceforge.jp/eclipse/updates/5Site toincludetosearchsiteFinsih6UpdatesSelectthe featurestoinstall“3.1.x”Eclipse3.27Finish8EclipseviEclpisepropertiesP
5. WebContentHelloWorl.jsp<%@pagecontentType="text/html;charset=UTF-8"%>
<%@taglibprefix="s"uri="/struts-tags"%><html><head><title>HelloWorld</title></head><body><h2><s:textname="HelloWorld"/></h2><h2><s:propertyvalue="%{getText('HelloWorld')}"/></h2></body></html>
6. http://localhost:8080/Struts2_i18n/HelloWorld.jsp1
17. “”2
2
Struts1.xStruts 2.0Struts——UIgetTextlabel
<s:textfieldname="name"label="%{getText('UserName')}"/>
Struts2.0propertiesStruts
1. package2. package.propertiespackage_xx_XX.properties3. ActionActionActionActionActionproperties
ActonOnetitle“”titleActionTwo“”4. <s:i18n>properties Struts 2.0Tag <s:i18n>
<s:i18nname="xxxxx"></s:i18n>xxxxxStruts
Struts2.03
3
ChildActiongetText("user.title")Struts2.0
1. ChildAction_xx_XX.propertiesChildAction.properties2. ChildActionMyInterface.properties
3. ChildActionParentActionpropertiesParentAction.properties4. ChildActionModelDrivengetModel()5. package.properties6.7. ValueStackuserusertitle;8. struts.properties1;9. user.title
runtimeStruts
1. OGNL${}validation.require=${getText(fileName)}isrequired
2. java.text.MessageFormat{ 0,number|date|time|choice,}validation.between=Datemustbetween{0,date,short}and{1,date,short}
1. value0value1...valueN<s:textname="validation.required"value0="UserName"/>
2. paramparam<s:textname="validation.required"><s:paramvalue="UserName"/></s:text>
——StrutsActionContext.getContext().setLocale(Localearg)ScenarioStruts 2.0i18nInterceptorInterceptorActioni18n"request_locale"LocaleLocaleLocalesession“WW_TRANS_I18N_LOCALE”
packagetutorial;
importjava.util.Hashtable;importjava.util.Locale;importjava.util.Map;
publicclassLocales{publicMap<String,Locale>getLocales(){Map<String,Locale>locales=newHashtable<String,Locale>(2);locales.put("AmericanEnglish",Locale.US);locales.put("SimplifiedChinese",Locale.CHINA);returnlocales;}}
tutorial/Locales.java
<%@taglibprefix="s"uri="/struts-tags"%><scripttype="text/javascript"><!--functionlangSelecter_onChanged(){document.langForm.submit();}//--></script>
<s:setname="SESSION_LOCALE"value="#session['WW_TRANS_I18N_LOCALE']"/><s:beanid="locales"name="tutorial.Locales"/><formaction="<s:urlincludeParams="get"encode="true"/>"name="langForm"style="background-color:powderblue;padding-top:4px;padding-bottom:4px;">Language:<s:selectlabel="Language"list="#locales.locales"listKey="value"listValue="key"value="#SESSION_LOCALE==null?locale:#SESSION_LOCALE"name="request_locale"id="langSelecter"onchange="langSelecter_onChanged()"theme="simple"/></form>LangSelector.jsp
LangSelector.jspLocalesMaplocalesselectLangSelector<s:form>Javascript“reqeust_locale”Actionsession“WW_TRANS_I18N_LOCALE”locale
LangSelector.jspJSP<s:includevalue="/LangSelector.jsp"/>
1HellloWorld.jsp<body>struts.xmlAction<actionname="HelloWorld"><result>/HelloWorld.jsp</result></action>
JSPJSPAction<actionname="*"><result>/{1}.jsp</result></action>
http://localhost:8080/Struts2_i18n/HelloWorld.action4
3 HelloWorld.action
“AmericanEnglish”5
4 HelloWorld.action
ActionActionJSPJSPStruts
postedon2006-11-0119:06Max(2326)(23): Struts2.0
Struts 2.0http://www.blogjava.net/max/category/16130.html
StrutsMVC2WebWebStruts
MVC2TagLibrary
“”Struts
“”
WebStruts2.0
1.1. ApacheStruts2.0
2. Eclipse3.2Web
File\New\Project1
1Web\DynamicWeb Project“Next”2
2Web“Project Name”Struts2_HelloWorld“New”
3“Apache\Apache Tomatv5.5”“Next”
4“Finish”
3. Struts2.0libjarbuildpath
5Struts 2.0libctr+aEclipse“Project Explorer”Struts2_HelloWorld\WebContent\WEB-INF\libEclipse“Project Explorer”jarStruts2_HelloWorld\JavaResources:src\Libraries\WebAppLibraries6
6ProjectExplorer
4. web.xml
<?xmlversion="1.0"encoding="ISO-8859-1"?><!DOCTYPEweb-appPUBLIC"-//SunMicrosystems,Inc.//DTDWebApplication2.3//EN""http://java.sun.com/dtd/web-app_2_3.dtd"><web-app><display-name>Struts2.0HelloWorld</display-name><filter><filter-name>struts2</filter-name><filter-class>org.apache.struts2.dispatcher.FilterDispatcher</filter-class></filter><filter-mapping><filter-name>struts2</filter-name><url-pattern>/*</url-pattern></filter-mapping><welcome-file-list><welcome-file>index.html</welcome-file></welcome-file-list></web-app>
5. struts.xml
Struts2_HelloWorld\JavaResources:src7
7 Other“Other”8
8“Next”9
9“Filename”sturts.xml“Finish”struts.xml
<!DOCTYPEstrutsPUBLIC"-//ApacheSoftwareFoundation//DTDStrutsConfiguration2.0//EN""http://struts.apache.org/dtds/struts-2.0.dtd"><struts><includefile="struts-default.xml"/></struts>
6. index.html
Struts2_HelloWorld\WebContent10
10 Other“Other”11
11Web\HTML“Next”12
12HTML“File Name”index.html“Next”13
13“Finish”index.html
<!DOCTYPEHTMLPUBLIC"-//W3C//DTDHTML4.01Transitional//EN"><html><head><metahttp-equiv="Content-Type"content="text/html;charset=UTF-8"><title>HelloWorld</title></head><body><h3>HelloWorld!</h3>
</body></html>
7. tomcat
Struts_HelloWorld14
14“Export\WAR file”15
15“Web\WARfile”“Next”16
16war%tomcat%\webapps\Struts2_HelloWorld.war“Finish”
8. tomcat
Internet Explorerhttp://localhost:8080/Struts2_HelloWorld/17
17 HelloWorld
2. Struts2.0——HelloWorld
1. package
Struts2_HelloWorld\JavaResources:src18
18 "“New\Package”19
19Java“Name”tutorial“Finish”
2. HelloWorld.java
Struts2_HelloWorld\JavaResources:src\tutorial20
20“New\Class”21
21 Java“Name”HelloWorld“Superclass”com.opensymphony.xwork2.ActionSupport“Finish”HelloWorld.java
packagetutorial;
importcom.opensymphony.xwork2.ActionSupport;
publicclassHelloWorldextendsActionSupport{privateStringname;publicStringgetName(){returnname;
}publicvoidsetName(Stringname){this.name=name;}publicStringexecute(){name="Hello,"+name+"!";returnSUCCESS;}}
3. struts.xmlaction(mapping)<!DOCTYPEstrutsPUBLIC"-//ApacheSoftwareFoundation//DTDStrutsConfiguration2.0//EN""http://struts.apache.org/dtds/struts-2.0.dtd"><struts><includefile="struts-default.xml"/><packagename="tutorial"extends="struts-default"><actionname="HelloWorld"class="tutorial.HelloWorld"><result>HelloWorld.jsp</result></action></package></struts>
4. SayHello.jsp
“index.html”22
22“Next”,23
23JSP“File name”SayHello.jsp“Next”24
24“Finish”SayHello.jsp
<%@pagecontentType="text/html;charset=UTF-8"%><%@taglibprefix="s"uri="/struts-tags"%><!DOCTYPEHTMLPUBLIC"-//W3C//DTDHTML4.01Transitional//EN"><html><head><title>SayHello</title></head><body><h3>Say"Hello"to:</h3>
<s:formaction="HelloWorld">Name:<s:textfieldname="name"/><s:submit/></s:form></body></html>
5. HelloWorld.jsp()HelloWorld.jsp<%@pagecontentType="text/html;charset=UTF-8"%><%@taglibprefix="s"uri="/struts-tags"%><!DOCTYPEHTMLPUBLIC"-//W3C//DTDHTML4.01Transitional//EN"><html><head><title>Hello</title></head><body><h3><s:propertyvalue="name"/></h3></body></html>
6.
tomcat, tomcatwebappsStruts2_HelloWorld.warStruts2_HelloWorld“tomcat”
7. tomcat
Internet Explorerhttp://localhost:8080/Struts2_HelloWorld/SayHello.jsp25
25 SayHello.jsp“Name”WorldSubmitHelloWorld.jsp26
26HelloWorld.jsp
3. HelloWorld
StrutsStruts2.0
1. JUnit
Struts2_HelloWorld\JavaResources:src\tutorial27
27“Next\Other”
28“Java\JUnit\JUnitTestCase”“Next”
29JUnit“NewJUnit4 test”“Name”HelloWorldTest“Classundertest”tutorial.HelloWorld“Next”
30HelloWorld\executeFinishHelloWorldTest.javaIconJUnit 4jar
Struts2_HelloWorld
31“BuildPath\Add Libararis”32
32“JUnit”“Next”
33“JUnit4”“Finish”HelloWorldTest.java
packagetutorial;
importstaticorg.junit.Assert.assertTrue;
importorg.junit.Test;
importcom.opensymphony.xwork2.ActionSupport;
publicclassHelloWorldTest{
@TestpublicvoidtestExecute(){HelloWorldhello=newHelloWorld();hello.setName("World");Stringresult=hello.execute();assertTrue("Expectedasuccessresult!",ActionSupport.SUCCESS.equals(result));
finalStringmsg="Hello,World!";assertTrue("Expectedthedefaultmessage!",msg.equals(hello.getName()));}
}
2.
Struts2_HelloWorld\JavaResources:src\tutorial\HelloWorldTest.java34
34“RunAs\JUnit Test”JUnit35
35JUnit35
4.
Web->Action->Struts
WebWeb Struts2.0
postedon2006-10-1018:35Max(12691)(112): Struts2.0
2:1 2
:
#re:Struts2.02006-10-2622:57| esmilesHelloWorld.jsp<s:propertyname="name"/>namevalue<s:propertyvalue="name"/>
#re:Struts2.02006-10-2709:12| Max@esmilesThanks
#re:Struts2.02006-10-2714:48| Max
@tomcatstruts.propertiesStruts2.0struts.xmlstruts.propertiesWEB-INF/classes/1struts.xml2struts.propertiesStruts 2.0Runtime
#re:Struts2.02006-10-3010:44| Max
@struts-default.xmlstruts2-core-2.0.0.jar
#re:Struts2.02006-11-0223:14| Tin
MaxWebWork http://webwork.javascud.org/http://wiki.javascud.org/display/ww2cndoc/WebWorkWebWork2.2Struts2.0.1WebWork 2.2.xWebWork2
#re:Struts2.02006-11-1000:47| Goingmm[]
struts2-all-2.0.1.jarstruts2-core-2.0.1.jar2struts-default.xmlstruts-2.0.1libjar562.0.1struts2-extras-2.0.0.jar
#re:Struts2.02006-11-2221:42|default-config.xmlincludestruts.xml
#re:Struts2.02006-11-2618:32| MaxDefault-config.xmlcontainssomeinterceptorstacksandcommonconfigurations.Includingitcanhelpyoutocreateactioneasier
#re:Struts2.02006-11-2712:36|
default-config.xmldefault-config.xmljarstruts.xmldefault-config.xml
#re:Struts2.02006-11-2823:52| Maxstruts.xmldefault-config.xml
#re:Struts2.02006-12-0213:26| jakki@Max:Couldnotfindorerrorinstruts.propertiesjava.lang.IllegalStateException:struts.propertiesmissing
#re:Struts2.02006-12-0418:50|struts.propertiesclasses
#re:Struts2.02006-12-0510:52| kevin666888SayHello.jsp“”
"Hello,?=?!"
#re:Struts2.02006-12-0518:34| MaxHelloWorld.jsp<%@pagecontentType="text/html; charset=UTF-8"%>
#re:Struts2.02006-12-0721:20| konhon...,
#re:Struts2.02006-12-1415:04| xanbio@copy
#re:Struts2.02006-12-1415:07| xanbio1.classpathstruts.properties2.tomcatconttextreloadtrue
#2007-04-0317:44| lhxregister.jsp action“user.username”,<%@pagecontentType="text/html;charset=GBK"%><%@taglibprefix="s"uri="/struts-tags"%><html><head><metahttp-equiv="Content-Type"content="text/html;charset=gb2312"><title>SignOn</title></head><body><s:formaction="RegisterAction"><table><tr><td></td><td><s:textfieldkey="user.username"/></td></tr><tr><td></td><td><s:textfieldkey="user.address"/></td></tr>
<tr><tdcolspan="2"><s:submit/></td></tr></table></s:form>
#re:Struts2.02007-04-0722:56| Max@lhx<%@pagecontentType="text/html;charset=GBK"%>GBK<metahttp-equiv="Content-Type"content="text/html;charset=gb2312">gb2312utf-8
#re:Struts2.02007-04-0914:53| open@
HelloWorld
HelloWorld.action
#re:Struts2.02007-04-1813:36| jiajiatomcatstrurs2default-config.xmlstruts.xml
#re:Struts2.02007-04-1823:05| [email protected],struts-plugin.xml,struts.xml
#re:Struts2.02007-04-1909:49| jiajia
maxstruts-plugin.xmljar
#re:Struts2.02007-04-1923:19| Max
@jiajiastruts-plugin.xmlpluginjarstruts2-spring-plugin-2.0.6.jar
#re:Struts2.02007-04-1923:28| [email protected] 2filterweb.xml<web-app></web-app><filter><filter-name>struts2</filter-name><filter-class>org.apache.struts2.dispatcher.FilterDispatcher</filter-class></filter>
<filter-mapping><filter-name>struts2</filter-name><url-pattern>/*</url-pattern></filter-mapping>
#re:Struts2.02007-05-1017:31| gpiaofei2006
SayHello.jspHellonull
#re:Struts2.02007-05-1313:58| gpiaofei2006#re:Struts2.02006-10-2622:57|esmiles
HelloWorld.jsp<s:propertyname="name"/>
namevalue<s:propertyvalue="name"/>
HelloWorld.jsp<s:propertyname="name"/>Hello,null;
Struts 2.0Taghttp://www.blogjava.net/max/category/16130.html
Struts 2.0 Struts2.0 Struts 2.0 [email protected]
Struts1.xStruts2.0TagLibrary
Struts1.x Struts2.0HTMLTilesLogicBean
URI“/struts-tags”UIUI
expressionlanguages EL OGNLJSTLGroovyVelcity
“”“”Struts
JSPStruts 2.0JSP<%@taglibprefix="s"uri="/struts-tags"%>
1. UIifelseifelse
test Boolean elseid Object/String idUIHTMLid
<%@pagecontentType="text/html;charset=UTF-8"%>
<%@taglibprefix="s"uri="/struts-tags"%><!DOCTYPEHTMLPUBLIC"-//W3C//DTDHTML4.01Transitional//EN"><html><head><title>ConditionFlow</title></head><body><h3>ConditionFlow</h3><!--#parameters.name[0]nameincludeparamname#parameters#parameters.name
includeincluded#parametersrequest.getParameter("name")--><s:setname="name"value="<%="'"+request.getParameter("name")+"'"%>"/><s:iftest="#name=='Max'">Max'sfilehere</s:if><s:elseiftest="#name=='Scott'">Scott'sfilehere</s:elseif><s:else>Other'sfilehere</s:else></body></html>1condition.jsp
iterator
java.util.Collectionjava.util.Iterator
status String IteratorStatusvalue Object/String iteratableListid Object/String idUIHTMLid
<%@pagecontentType="text/html;charset=UTF-8"%><%@pageimport="java.util.List"%><%@pageimport="java.util.ArrayList"%><%@taglibprefix="s"uri="/struts-tags"%>
<!DOCTYPEHTMLPUBLIC"-//W3C//DTDHTML4.01Transitional//EN"><%Listlist=newArrayList();list.add("Max");list.add("Scott");list.add("Jeffry");list.add("Joe");list.add("Kelvin");request.setAttribute("names",list);%><html><head><title>Iterator</title></head><body><h3>Names:</h3><!--1propertyiterator2statusstutsiterator#stutsIteratorStatusIteratorS
tatus--><ol><s:iteratorvalue="#request.names"status="stuts"><s:iftest="#stuts.odd==true"><li>White<s:property/></li></s:if><s:else><listyle="background-color:gray"><s:property/></li></s:else></s:iterator></ol></body></html>2iterator.jsp
i18n
textaction
value Object/String com.xxxx.resources.AppMsgid Object/String idUIHTMLid
HelloWorld=HelloWrold!3classes\ ApplicationMessages.properties
<%@pagecontentType="text/html;charset=UTF-8"%><%@taglibprefix="s"uri="/struts-tags"%>
<!DOCTYPEHTMLPUBLIC"-//W3C//DTDHTML4.01Transitional//EN"><html><head><title>Internationization</title></head><body><h3><s:i18nname="ApplicationMessages"><s:textname="HelloWorld"/></s:i18n></h3></body></html>3i18n.jsp
include
servletservletjsp
value String jspservletid Object/String idUIHTMLid
<%@pagecontentType="text/html;charset=UTF-8"%><%@taglibprefix="s"uri="/struts-tags"%>
<!DOCTYPEHTMLPUBLIC"-//W3C//DTDHTML4.01Transitional//EN"><html><head><title>Iterator</title>
</head><body><h3>InteratorPage</h3><s:includevalue="/condition.jsp"><s:paramname="name">Max</s:param></s:include><h3>i18n</h3><s:includevalue="/i18n.jsp"/></body></html>4include.jsp
param
,includebean. name,ComponentaddParameter(String,Object),UnnamedParametric(TextTag)
value,valuetext,:<paramname="color">blue</param><!--(A)--><paramname="color"value="blue"/><!--(B)-->(A)Stringstatck.(B)java.lang.Objectstatck.
name Stringvalue String valueid Object/String idUIHTMLid
4
set
set,:
name String
scope String ,application,session,request,page,action.
value Object/Stringid Object/String idUIHTMLid
1
text
actionresource bundle,message,tagbodymessage,tagbody,messagenamemessage
name Stringid Object/String idUIHTMLid
3
url
url,"param"request
includeParams'all''get', param,
<%@pagecontentType="text/html;charset=UTF-8"%><%@taglibprefix="s"uri="/struts-tags"%><!DOCTYPEHTMLPUBLIC"-//W3C//DTDHTML4.01Transitional//EN"><html><head><title>URL</title></head><body><h3>URL</h3><ahref='<s:urlvalue="/i18n.jsp"/>'>i18n</a><br/><s:urlid="url"value="/condition.jsp"><s:paramname="name">Max</s:param></s:url><s:ahref="%{url}">if\elseif\else</s:a></body></html>5url.jsp
property
'value',value,
default String nulldefaultescape true Booelean escapeHTMLvalue Objectid Object/String idUIHTMLid
2
2. UI
UIUIUIUIStruts1.xHTMLStrutsdoubleselecttimepickeroptiontransferselect
http://wiki.javascud.org/display/ww2cndoc/TagsWebWork2
http://cwiki.apache.org/WW/tag-reference.htmlTagDevelopersGuide
Struts2.0ShowCase
/**$Id:UITagExample.java4203852006-07-1000:57:05Zmrdon$**Copyright2006TheApacheSoftwareFoundation.**LicensedundertheApacheLicense,Version2.0(the"License");*youmaynotusethisfileexceptincompliancewiththeLicense.*YoumayobtainacopyoftheLicenseat**http://www.apache.org/licenses/LICENSE-2.0**Unlessrequiredbyapplicablelaworagreedtoinwriting,software*distributedundertheLicenseisdistributedonan"ASIS"BASIS,*WITHOUTWARRANTIESORCONDITIONSOFANYKIND,eitherexpressorimplied.*SeetheLicenseforthespecificlanguagegoverningpermis
sionsand*limitationsundertheLicense.*/packageorg.apache.struts2.showcase;
importorg.apache.struts2.ServletActionContext;importcom.opensymphony.xwork2.ActionSupport;importcom.opensymphony.xwork2.Validateable;importcom.opensymphony.xwork2.util.OgnlValueStack;
importjava.util.ArrayList;importjava.util.Collections;importjava.util.Date;importjava.util.HashMap;importjava.util.List;importjava.util.Map;importjava.io.File;
/***/publicclassUITagExampleextendsActionSupportimplementsValidateable{privatestaticfinallongserialVersionUID=-94044809860988047L;Stringname;Datebirthday;Stringbio;StringfavoriteColor;Listfriends;booleanlegalAge;Stringstate;Stringregion;Filepicture;StringpictureContentType;StringpictureFileName;StringfavouriteLanguage;StringfavouriteVehicalType="MotorcycleKey";
StringfavouriteVehicalSpecific="YamahaKey";ListleftSideCartoonCharacters;ListrightSideCartoonCharacters;ListfavouriteLanguages=newArrayList();ListvehicalTypeList=newArrayList();MapvehicalSpecificMap=newHashMap();Stringthoughts;publicUITagExample(){favouriteLanguages.add(newLanguage("EnglishKey","EnglishLanguage"));favouriteLanguages.add(newLanguage("FrenchKey","FrenchLanguage"));favouriteLanguages.add(newLanguage("SpanishKey","SpanishLanguage"));VehicalTypecar=newVehicalType("CarKey","Car");VehicalTypemotorcycle=newVehicalType("MotorcycleKey","Motorcycle");vehicalTypeList.add(car);vehicalTypeList.add(motorcycle);Listcars=newArrayList();cars.add(newVehicalSpecific("MercedesKey","Mercedes"));cars.add(newVehicalSpecific("HondaKey","Honda"));cars.add(newVehicalSpecific("FordKey","Ford"));Listmotorcycles=newArrayList();motorcycles.add(newVehicalSpecific("SuzukiKey","Suzuki"));motorcycles.add(newVehicalSpecific("YamahaKey","Yamaha"));
vehicalSpecificMap.put(car,cars);vehicalSpecificMap.put(motorcycle,motorcycles);}publicListgetLeftSideCartoonCharacters(){returnleftSideCartoonCharacters;}publicvoidsetLeftSideCartoonCharacters(ListleftSideCartoonCharacters){this.leftSideCartoonCharacters=leftSideCartoonCharacters;}publicListgetRightSideCartoonCharacters(){returnrightSideCartoonCharacters;}publicvoidsetRightSideCartoonCharacters(ListrightSideCartoonCharacters){this.rightSideCartoonCharacters=rightSideCartoonCharacters;}publicStringgetFavouriteVehicalType(){returnfavouriteVehicalType;}publicvoidsetFavouriteVehicalType(StringfavouriteVehicalType){this.favouriteVehicalType=favouriteVehicalType;}publicStringgetFavouriteVehicalSpecific(){returnfavouriteVehicalSpecific;}publicvoidsetFavouriteVehicalSpecific(StringfavouriteVehicalSpecific){
this.favouriteVehicalSpecific=favouriteVehicalSpecific;}publicListgetVehicalTypeList(){returnvehicalTypeList;}publicListgetVehicalSpecificList(){OgnlValueStackstack=ServletActionContext.getValueStack(ServletActionContext.getRequest());ObjectvehicalType=stack.findValue("top");if(vehicalType!=null&&vehicalTypeinstanceofVehicalType){Listl=(List)vehicalSpecificMap.get(vehicalType);returnl;}returnCollections.EMPTY_LIST;}publicListgetFavouriteLanguages(){returnfavouriteLanguages;}
publicStringexecute()throwsException{returnSUCCESS;}
/* GettersandSetters */publicStringdoSubmit(){returnSUCCESS;}//===innerclasspublicstaticclassLanguage{Stringdescription;Stringkey;
publicLanguage(Stringkey,Stringdescription){this.key=key;this.description=description;}publicStringgetKey(){returnkey;}publicStringgetDescription(){returndescription;}}publicstaticclassVehicalType{Stringkey;Stringdescription;publicVehicalType(Stringkey,Stringdescription){this.key=key;this.description=description;}publicStringgetKey(){returnthis.key;}publicStringgetDescription(){returnthis.description;}publicbooleanequals(Objectobj){if(!(objinstanceofVehicalType)){returnfalse;}else{returnkey.equals(((VehicalType)obj).getKey());}}publicinthashCode(){returnkey.hashCode();}
}publicstaticclassVehicalSpecific{Stringkey;Stringdescription;publicVehicalSpecific(Stringkey,Stringdescription){this.key=key;this.description=description;}publicStringgetKey(){returnthis.key;}publicStringgetDescription(){returnthis.description;}publicbooleanequals(Objectobj){if(!(objinstanceofVehicalSpecific)){returnfalse;}else{returnkey.equals(((VehicalSpecific)obj).getKey());}}publicinthashCode(){returnkey.hashCode();}}}
6 org.apache.struts2.showcase.UITagExample.java
<%@pagecontentType="text/html;charset=UTF-8"pageEncoding="UTF-8"%><%@taglibprefix="s"uri="/struts-tags"%><html><head><title>UITagsExample</title><s:head/></head>
<body>
<s:actionerror/><s:actionmessage/><s:fielderror/>
<s:formaction="exampleSubmit"method="post"enctype="multipart/form-data"tooltipConfig="#{'jsTooltipEnabled':'true'}"><s:textfieldlabel="Name"name="name"tooltip="EnteryourNamehere"/>
<s:datepickertooltip="SelectYourBirthday"label="Birthday"name="birthday"/>
<s:textareatooltip="EnteryourBiography"label="Biograph"name="bio"cols="20"rows="3"/>
<s:selecttooltip="ChooseYourFavouriteColor"label="FavoriteColor"list="{'Red','Blue','Green'}"name="favoriteColor"emptyOption="true"headerKey="None"headerValue="None"/>
<s:selecttooltip="ChooseYourFavouriteLanguage"label="FavouriteLanguage"
list="favouriteLanguages"name="favouriteLanguage"listKey="key"listValue="description"emptyOption="true"headerKey="None"headerValue="None"/>
<s:checkboxlisttooltip="ChooseyourFriends"label="Friends"list="{'Patrick','Jason','Jay','Toby','Rene'}"name="friends"/>
<s:checkboxtooltip="ConfirmedthatyourareOver18"label="Age18+"name="legalAge"/>
<s:doubleselecttooltip="ChooseYourState"label="State"name="region"list="{'North','South'}"value="'South'"doubleValue="'Florida'"doubleList="top=='North'?{'Oregon','Washington'}:{'Texas','Florida'}"doubleName="state"headerKey="-1"headerValue="----------PleaseSelect----------"emptyOption="true"/>
<s:doubleselecttooltip="ChooseyourVehical"label="FavouriteVehical"name="favouriteVehicalType"list="vehicalTypeList"
listKey="key"listValue="description"value="'MotorcycleKey'"doubleValue="'YamahaKey'"doubleList="vehicalSpecificList"doubleListKey="key"doubleListValue="description"doubleName="favouriteVehicalSpecific"headerKey="-1"headerValue="----------PleaseSelect----------"emptyOption="true"/>
<s:filetooltip="UploadYourPicture"label="Picture"name="picture"/><s:optiontransferselecttooltip="SelectYourFavouriteCartoonCharacters"label="FavouriteCartoonsCharacters"name="leftSideCartoonCharacters"leftTitle="LeftTitle"rightTitle="RightTitle"list="{'Popeye','He-Man','Spiderman'}"multiple="true"headerKey="headerKey"headerValue="---PleaseSelect---"emptyOption="true"doubleList="{'Superman','MickeyMouse','DonaldDuck'}"doubleName="rightSideCartoonCharacters"doubleHeaderKey="doubleHeaderKey"doubleHeaderValue="---PleaseSelect---"doubleEmptyOption="true"doubleMultiple="true"/><s:textarea
label="YourThougths"name="thoughts"tooltip="Enteryourthoughtshere"/><s:submitonclick="alert('aaaa');"/><s:resetonclick="alert('bbbb');"/></s:form></body></html>6example.jsp
<actionname="example"class="org.apache.struts2.showcase.UITagExample"><result>example.jsp</result><resultname="input">example.jsp</result></action>6struts.xml
postedon2006-10-1812:02Max(7119)(56): Struts2.0
:
#re:Struts2.0Tag2006-12-0111:21| lxfstruts
#re:Struts2.0Tag2006-12-0116:36| Max<s:form>theme="simple"form:<s:formaction="Login"method="POST"theme="simple"><table><tr><td>Username:<s:textfieldname="name"label="Username"/></td>
<td>Password:<s:passwordname="password"label="Password"/></td></tr></table></s:form>