dwr轻松上路(二)

二、如何对浏览器声明可使用的java code?

  1. 第一步我们当然要首先写一个java 类了,加入类文件内容如下所示:package com.zb.webcontrol.simpletext;
    public class Demo {
          public int addInt(int num)
        {
         return num + 1;
        }}
  2. 第二步修改dwr.xml,在<allow></allow>之间,发布该类 <create creator="new" javascript="SimpleText">
          <param name="class" value="com.zb.webcontrol.simpletext.Demo"/>
        </create>
  3. 大功告成了,http://localhost:8080/[YOUR-WEBAPP]/dwr会显示

    Classes known to DWR:

    • SimpleText (com.zb.webcontrol.simpletext.Demo)单击即可进行测试

      Methods For: SimpleText (com.zb.webcontrol.simpletext.Demo)

      To use this class in your javascript you will need the following script includes:

        <script type='text/javascript' src='/DwrStudy/dwr/interface/SimpleText.js'></script>
        <script type='text/javascript' src='/DwrStudy/dwr/engine.js'></script>
      

      In addition there is an optional utility script:

        <script type='text/javascript' src='/DwrStudy/dwr/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 17 declared methods:

      • addInt( ); <script type="text/javascript"> var reply3 = function(data) { if (data != null && typeof data == 'object') alert(dwr.util.toDescriptiveString(data, 2)); else dwr.util.setValue('d3', dwr.util.toDescriptiveString(data, 1)); } </script>
      • 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

      Other Links

  4. 简单吧,连web 前端如何使用该类也做了说明

     

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值