1、在web.xml中EncodingFilter的位置應(yīng)該在Struts2的FilterDispatcher之前,道理很簡單,要先調(diào)整字符集,再進入Action。
2、如果使用Urlrewrite,要指定filter-mapping的dispatcher方式,如下
<filter-mapping>
<filter-name>Struts2</filter-name>
<url-pattern>/*</url-pattern>
<dispatcher>REQUEST</dispatcher>
<dispatcher>FORWARD</dispatcher>
</filter-mapping>
3、在做上傳文件的時候,要在web.xml中增加ActionContextCleanUp這個filter,如果不增加,會發(fā)生第一次上傳取不到文件的情況
<filter>
<filter-name>struts-cleanup</filter-name>
<filter-class>org.apache.struts2.dispatcher.ActionContextCleanUp</filter-class>
</filter>
<filter-mapping>
<filter-name>struts-cleanup</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
按照Struts2的API,filter的順序是
struts-cleanup filter
SiteMesh filter
FilterDispatcher
4、在Apache+Resin的情況下,要在WEB-INF下增加resin-web.xml,該文件只針對Resin有效,作用是指定后綴與 Resin的Servlet引擎匹配,要不然從Apache轉(zhuǎn)發(fā)過去的請求到Resin后會出現(xiàn)404的情況,resin-web.xml舉例如下:
<web-app xmlns="http://caucho.com/ns/resin">
<servlet-mapping url-pattern='*.bbscs' servlet-name='plugin_match'/>
</web-app>
5、在使用<s:url/>標(biāo)簽的時候,會出現(xiàn)將get或post數(shù)值帶入url參數(shù)的情況,如果不需要這些參數(shù),可以在struts.properties文件中設(shè)置
struts.url.includeParams=none
或是在<s:url/>標(biāo)記中將includeParams屬性設(shè)為none
另外還有兩個值
all,是把get和post中的參數(shù)加入到url參數(shù)中
get,是只把get中的參數(shù)加入到url參數(shù)中
6、與webwork基本相同,Struts2提供了幾種ui.theme,有xhtml、css_xhtml、simple等等,在 struts.properties中可以設(shè)置使用何種theme,這一點很關(guān)鍵,不同的theme,struts的tag會生成不同的html代碼,而 且在某些情況下這些theme不能滿足頁面要求,則需要自己進行擴展了,這些theme都是由freemarker寫的,仿照這寫就可以。
7、單個checkbox的標(biāo)記庫好像只能返回boolean的值,如果在數(shù)據(jù)庫中設(shè)計為int型,則需要做一些轉(zhuǎn)換,這一點我覺得不如Struts1.x的方便。
8、總體來說Struts2的標(biāo)記庫使用上比Struts1.x的方便,頁面整體也比較簡潔,Struts2采用stack的方式存取數(shù)據(jù),與Struts1相比各有千秋吧。
Struts2主要延續(xù)自webwork,以前使用webwork的朋友轉(zhuǎn)過來并不困難,Struts2的幾個核心的部分,比如攔截器、Result Configuration、OGNL stack等等還是需要仔細的體會,深入了解,才能做出優(yōu)秀的系統(tǒng)。