日期:2014-05-16  浏览次数:20744 次

dwr简单问题
首先dwr.xml web.xml配置都是正确的,下面测试结果可以说明:
http://localhost:8080/help/dwr/test/Test

Methods For: Test (test)

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

  <script type='text/javascript' src='/help/dwr/interface/Test.js'></script>
  <script type='text/javascript' src='/help/dwr/engine.js'></script>

In addition there is an optional utility script:

  <script type='text/javascript' src='/help/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.
method1( ); "success"
getData( ); null
wait( ); 

jsp页面:导入路径应该也没有问题,在dwr方法中用alert(Test.getData)测试弹出
function (callback) {
  return dwr.engine._execute(Test._path, "Test", "getData", arguments);
}
但是alert(Test.getData())就没有反应。问题一


<%@ page language="java" contentType="text/html; charset=utf-8"
  pageEncoding="utf-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta >
<title>Insert title here</title>
</head>
  <script type='text/javascript' src='/help/dwr/interface/Test.js'></script>
  <script type='text/javascript' src='/help/dwr/engine.js'></script>
  <script type='text/javascript' src='/help/dwr/util.js'></script>
  
  <script type="text/javascript">
  function dwr(){
Test.getData(); 
  }
</script>  
<body>
<button onclick="dwr()"></button>
</body>
</html>


点击button没有任何反应。问题二
在线等。。。谢谢


------解决方案--------------------
这个问题我前两天遇到了,测试的时候可以显示值,但是页面运行的时候不会弹出值, 就是路径问题


<script type="text/javascript" src="<%=path%>/dwr/engine.js"></script>
<script type="text/javascript" src="<%=path%>/dwr/interface/helloDwr.js"></script>