Struts2.0与DWR2.0 的整和

DWR2.0默认支持webwork,在网上找了些资料有兄弟已经走在了我前面了,呵呵。不过我已经将其打包成了dwr4struts2.jar,见附件。

dwr.xml文件:

xml 代码
  1. <?xml version="1.0" encoding="UTF-8"?>     
  2. <!DOCTYPE dwr PUBLIC "-//GetAhead Limited//DTD Direct Web Remoting 2.0//EN" "http://www.getahead.ltd.uk/dwr/dwr20.dtd">     
  3. <dwr>     
  4.     <allow>     
  5.         <create creator="none" javascript="DWRAction">  
  6.             <param name="class" value="org.directwebremoting.struts2.DWRAction"/>  
  7.             <include method="execute"/>  
  8.         </create>  
  9.         <convert converter="bean" match="org.directwebremoting.struts2.ActionDefinition">  
  10.           <param name="include" value="namespace,action,method,executeResult" />  
  11.         </convert>  
  12.         <convert converter="bean" match="org.directwebremoting.struts2.AjaxResult"/>  
  13.         <!-- 相应的Struts2的Action -->  
  14.         <convert match="com.*.*Action" converter="bean"/>  
  15.         <!-- 如果有复杂类型要转换,如List中有多个JavaBean对象 -->  
  16.         <convert match="com.*.model.*Bean" converter="bean"/>  
  17.     </allow>  
  18. </dwr>  

 

testDwr.htm文件:

xml 代码
  1. <html>  
  2.     <head>  
  3.         <script type='text/javascript' src='/js/dwr/DWRActionUtil.js'></script>  
  4.         <script type='text/javascript' src='/dwr/interface/DWRAction.js'></script>  
  5.         <script type='text/javascript' src='/dwr/engine.js'></script>  
  6.         <script type='text/javascript' src='/dwr/util.js'></script>  
  7.         <script language="javascript">  
  8.                 function testDwr(){   
  9.                     DWRActionUtil.execute({namespace:'/',action:'special',executeResult:'false'}, 'frmDwr', writePage);   
  10.                 }   
  11.                 function writePage(data){                   alert("departure = "+data.departure);   
  12.                 }   
  13.         </script>  
  14.     </head>  
  15.     <body>  
  16.         <form name="frmDwr" method="post" action="" id="frmDwr">  
  17.             <input name="departure" value="PEK"/>  
  18.             <input type="button" value="测试" onclick="testDwr();">  
  19.         </form>  
  20.     </body>  
  21. </html>  

你可能感兴趣的:(JavaScript,bean,struts,DWR,Webwork,action)