二、如何对浏览器声明可使用的java code?
- 第一步我们当然要首先写一个java 类了,加入类文件内容如下所示:package com.zb.webcontrol.simpletext;
public class Demo {
public int addInt(int num)
{
return num + 1;
}} - 第二步修改dwr.xml,在<allow></allow>之间,发布该类 <create creator="new" javascript="SimpleText">
<param name="class" value="com.zb.webcontrol.simpletext.Demo"/>
</create> - 大功告成了,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
- Back to class index.
- SimpleText (com.zb.webcontrol.simpletext.Demo)单击即可进行测试
- 简单吧,连web 前端如何使用该类也做了说明