0 0

dwr 上使用json10

最近使用dwr传递json数据,dwr说是支持dojo,但是不明白这里的东西。希望有懂这方面的牛人不吝赐教,不胜感激!
这是
dwr.xml
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE dwr PUBLIC "-//GetAhead Limited//DTD Direct Web Remoting 3.0//EN" "http://getahead.org/dwr/dwr30.dtd">

<dwr>
<allow>

<create creator="new" javascript="Demo">
<param name="class" value="mlt.test.Demo" />
</create>
<convert match="mlt.test.Demo" converter="bean" />
</allow>
</dwr>

下面是一个测试页面

<html>
<head>
<script type='text/javascript' src='/zxdy/dwr/interface/Demo.js'>
</script>
<script type='text/javascript' src='/zxdy/dwr/engine.js'>
</script>
<script type='text/javascript' src='/zxdy/dwr/util.js'>
</script>

<script type="text/javascript">
var services = new dojox.rpc.Service( {
target : "../dwr/jsonrpc",
transport : "POST",
envelope : "JSON-RPC-1.0",
contentType : "application/json",
services : {
"Demo.sayHello" : {
returns : {
"type" : "string"
},
parameters : [ {
"type" : "string"
} ]
}
}
});

function update() {
var name = dojo.byId("demoName").value;
var deferred = services.Demo.sayHello(name);
deferred.addCallback(function(result) {
dojo.byId("demoReply").innerHTML = result;
});
}

</script>
</head>
<body>
<p>
Name:
<input type="text" id="demoName" />
<input value="Send" type="button" onclick="update()" />
<br />
Reply:
<span id="demoReply"></span>
</p>
</body>
</html>

下面是
web.xml的配置文件
 
<servlet>
<servlet-name>dwr-invoker</servlet-name>
<servlet-class>org.directwebremoting.servlet.DwrServlet</servlet-class><!--
This should NEVER be present in live -->
<init-param>
<param-name>debug</param-name>
<param-value>true</param-value>
</init-param>
<!-- Remove this unless you want to use active reverse ajax -->
<init-param>
<param-name>activeReverseAjaxEnabled</param-name>
<param-value>true</param-value>
</init-param>
<!-- By default DWR creates application scope objects when they are first
used. This creates them when the app-server is started -->
<init-param>
<param-name>initApplicationScopeCreatorsAtStartup</param-name>
<param-value>true</param-value>
</init-param>
<!-- WARNING: allowing JSON-RPC connections bypasses much of the security
protection that DWR gives you. Take this out if security is important -->
<init-param>
<param-name>jsonRpcEnabled</param-name>
<param-value>true</param-value>
</init-param>
<!-- WARNING: allowing JSONP connections bypasses much of the security
protection that DWR gives you. Take this out if security is important -->
<init-param>
<param-name>jsonpEnabled</param-name>
<param-value>true</param-value>
</init-param>
<!-- data: URLs are good for small images, but are slower, and could OOM
for larger images. Leave this out (or keep 'false') for anything but small
images -->
<init-param>
<param-name>preferDataUrlSchema</param-name>
<param-value>false</param-value>
</init-param>
<!-- This enables full streaming mode. It's probably better to leave this
out if you are running across the Internet -->
<init-param>
<param-name>maxWaitAfterWrite</param-name>
<param-value>-1</param-value>
</init-param>
<!-- For more information on these parameters, see: - http://getahead.org/dwr/server/servlet
- http://getahead.org/dwr/reverse-ajax/configuration -->
<load-on-startup>1</load-on-startup>
</servlet>

<servlet-mapping>
<servlet-name>dwr-invoker</servlet-name>
<url-pattern>/dwr/*</url-pattern>
</servlet-mapping>


上面的target 这个 这个在tomcat上跑 跑不通,javascript中的一个 还有这个target后面的 ../dwr/jsonrpc 是哪个jsonrpc 是怎么搞的,谁能给讲解下这些东西。搞不懂。
2012年2月27日 21:08
目前还没有答案

相关推荐

Global site tag (gtag.js) - Google Analytics