日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

ajax框架dwr开发

發布時間:2024/9/20 编程问答 24 豆豆
生活随笔 收集整理的這篇文章主要介紹了 ajax框架dwr开发 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
dwr實現AJAX非常先進。比如動態生成javaScript代碼;隱藏的HTTP協議,javascript用于java代碼交互的javaScript對象。
 自從我開始DWR感覺DWR是用javaScript對象去代替java類的對象去做某些事情。
 比如一個java類名為:ShowHello  當你在dwr.xml文件做了映射 javascrip對象叫 showHello 那么你在html文件或jsp文件中想使用ShowHello中的某些方法。那就可直接使用showHello就可以了。dwr就是這樣的功能。
 使用時要注意以下幾點:
   1.引入兩個包。dwr.jar,xalan.jar這個包一般的情況在高版中把這個jar包的類已經包含了。低版的tomcat要引入這個包??梢愿鶕闆r,先引入dwr.jar測試不成功,再引入xalan.jar。
   2.配置web.xml文件。
    具體的內容如下:
    <servlet>
       <servlet-name>kmweb</servlet-name>
       <servlet-class>uk.ltd.getahead.dwr.DWRServlet</servlet-class>
       <load-on-startup>1</load-on-startup>
       <init-param>
         <param-name>debug</param-name>
         <param-value>true</param-value>
       </init-param>
     </servlet>
    注意:debug這個參數一定要有,是用來測試的。
     <servlet-mapping>
       <servlet-name>kmweb</servlet-name>
       <url-pattern>/ajax/*</url-pattern>
     </servlet-mapping>  
   3.編寫dwr.xml文件
    <?xml version="1.0" encoding="UTF-8"?>
    <!DOCTYPE dwr PUBLIC
????        "-//GetAhead Limited//DTD Direct Web Remoting 1.0//EN"
        ????"http://www.getahead.ltd.uk/dwr/dwr10.dtd">
    <dwr>
       <allow>
         <create javascript="showName" creator="new">
         <param name="class" value="Test.A"/>
         <include method="addNode"/>
         </create>
       </allow>
    </dwr>
   這里面我已經寫了一例子。當你想在頁面中使用Test.A時就可以用showName來引用。include的意思就可showName對象可引用Test.A的哪些方法,不寫的話就是全部的方法。
上面的是用普通的方法。如果使用的spring框架的話。配置則是另外一種法。如下:
<create creator="spring" javascript="JSUserTree">
??????<param name="beanName" value="remoteUserTree"/>
??????<include method="addNode"/>
??????<include method="deleteNode"/>
??????<include method="renameNode"/>
??????<include method="getAllNodes"/>
</create>
4.編寫類。
5.測試(http://服務名字或IP:端口號/項目名/ajax/)如果出來index頁面就OK了
6.在測試index頁面中會出現Classes known to DWR:標題.下面是我測試是的一個例子:
showName (Test.A)
hitNum (Test.ReturnInt)
這就是類與js的對應關系. 點擊要要使用的類進入下一個頁面.如:
Methods For: hitNum (Test.ReturnInt)
To use this class in your javascript you will need the following script includes:
<script type='text/javascript' src='/exercise/ajax/interface/hitNum.js'></script>
<script type='text/javascript' src='/exercise/ajax/engine.js'></script>
In addition there is an optional utility script:
<script type='text/javascript' src='/exercise/ajax/util.js'></script>
Replies from DWR are shown with a yellow background if they are simple or in an alert box otherwise.
The inputs are evaluated as Javascript so strings must be quoted before execution.
There are 11 declared methods:
getHitNum( ); excute
setHitNum( ); excute
hashCode() is not available: Methods defined in java.lang.Object are not accessible
getClass() is not available: Methods defined in java.lang.Object are not accessible
wait() is not available: Methods defined in java.lang.Object are not accessible
wait() is not available: Methods defined in java.lang.Object are not accessible
wait() is not available: Methods defined in java.lang.Object are not accessible
equals() is not available: Methods defined in java.lang.Object are not accessible
notify() is not available: Methods defined in java.lang.Object are not accessible
notifyAll() is not available: Methods defined in java.lang.Object are not accessible
toString() is not available: Methods defined in java.lang.Object are not accessible
點擊可以進行測試了.測試成功的話.下一步就是編寫您的頁面.
7.在編寫您的頁面時一定要把
<script type='text/javascript' src='/exercise/ajax/interface/hitNum.js'></script>
<script type='text/javascript' src='/exercise/ajax/engine.js'></script>
類擬于上面的兩句話加入您的頁面.
8.在使用js時注意一定要一個回調函數做為最后一個參數(前提這個方法有返回值時).
9.編寫回調函數,回調函數的參數就是js對應相應類的方法返回值.
10.值得注意的是如果返回的不是原始類型則必須在dwr.xml中寫上如下:
<convert match="Test.Person" converter="bean"></convert>
match是返回的類型.converter表示是一個對象(確且我也不明白,明白后在寫一般情況就是這).

總結

以上是生活随笔為你收集整理的ajax框架dwr开发的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。