關於struts2

最近下載了struts2.0.6,可真大,解壓後大約150M,仔細看了一下,跑了其自帶幾個demo,並看了一下代碼,可以說基本和webwork2一樣的,核心基本沒改,感覺就修改了包名,說是struts和webwork合併,個人覺得是webwork利用struts這個招牌尋找市場,struts利用webwork2獲得重生,因爲在struts2基本看不到struts1的影子了。可惜,目前沒有關於struts2的書籍,感覺自帶的文檔排版比較亂(就和webwork2的一樣),很難尋找想要的信息,不過可以看webwork in action, 其實只要看了webwork in action的前五章,就可以理解struts2的架構了。

struts2對webwork的改進之處:

1.webwork.properties文件中變量現在可以配置在下列文件(這是struts2自帶文檔中的說的):

  struts-default.xml
  struts-plugin.xml(在每個plugin的jar包中)
  struts.xml(用constant元素)
  struts.properties(沒有默認文件,可選,與webwork.properties文件相似,每個項目可以有這個文件)
  web.xml

下面是struts2自帶文檔中的示例

Constant Example (struts.xml)
<struts>

  <constant name="struts.devMode" value="true" />

  ...

</struts>Constant Example (struts.properties)
struts.devMode = trueConstant Example (web.xml)
<web-app id="WebApp_9" version="2.4"
 xmlns="http://java.sun.com/xml/ns/j2ee"
 xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
 xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd">

    <filter>
        <filter-name>struts</filter-name>
        <filter-class>org.apache.struts2.dispatcher.FilterDispatcher</filter-class>
        <init-param>
         <param-name>struts.devMode</param-name>
         <param-value>true</param-value>
        </init-param>
    </filter>

    ...

</web-app>

2.加入了通配符的支持,這是在ww2中沒有的,如下:
<action name="*" >
      <result>/tutorial/{1}.jsp</result>
</action>



發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章