Struts2对WebWork的改进

最近下载了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自带文档中的示例

 
 
 
  1. Constant Example (struts.xml)  
  2. <struts>  
  3. <constant name="struts.devMode" value="true" />  
  4. ...   
  5. </struts>Constant Example (struts.properties)  
  6. struts.devMode = trueConstant Example (web.xml)  
  7. <web-app id="WebApp_9" version="2.4"   
  8. xmlns="http://java.sun.com/xml/ns/j2ee"   
  9. xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"   
  10. xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee   
  11. http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd">  
  12. <filter>  
  13. <filter-name>struts</filter-name>  
  14. <filter-class>org.apache.struts2.dispatcher.FilterDispatcher  
  15. </filter-class>  
  16. <init-param>  
  17. <param-name>struts.devMode</param-name>  
  18. <param-value>true</param-value>  
  19. </init-param>  
  20. </filter>  
  21. ...  
  22. </web-app> 

2.加入了通配符的支持,这是在ww2中没有的,如下:

 
 
 
  1. <action name="*" >  
  2. /tutorial/{1}.jsp  
  3. action>  

【编辑推荐】

  1. WebWork框架原理与应用(1)
  2. 用WebWork注册页面建立过程
  3. WebWork注入Servlet方法详解
  4. WebWork中返回INPUT的原因
  5. WebWork如何实现文件上传配置过程
THE END