1.AclServiceBean.java
public class AclServiceBean{
public String hello(){
return "回先生你好";
}
}
2.配置文件
web.xml
dwr-invoker
org.directwebremoting.servlet.DwrServlet
debug
true
dwr-invoker
/dwr/*
dwr.xml
spring 配置文件
beans.xml
3 jsp页面
function test2(){ aclManager.hello( function (data){ alert(data); } ); }对了我加载dwr.jar包了
可就是不好使呢?大家帮我出出主意,我这几天就要交项目,这个问题卡一天多了!!!!!!!!我QQ:444084929
commons-logging.jar包不能少.c从dwr2.*开始需要这个包。
把错误堆栈发上来看看
看了你的配置文件的方式,,,感觉你这根本就没有把SPRING跟DWR集成到一块,而是各自用各自的功能,这样DWR当然不知道还有这个SPRING这种框架了,更不知道如何使用BEAN了。。。
你在DWR .xml里有这个声明吗?
[code="xml"] xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:dwr="http://www.directwebremoting.org/schema/spring-dwr"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-2.0.xsd
http://www.directwebremoting.org/schema/spring-dwr
http://www.directwebremoting.org/schema/spring-dwr-2.0.xsd">[/code]
还有这个URLHANDLER有吗?
[code="xml"]
<!--
no 'id' required, HandlerMapping beans are automatically detected by
the DispatcherServlet
-->
dwrController
dwrController
dwrController
<!-- ...these are optional - used in debug mode... -->
<!--
test shows info on a service, use a url like /test/MyAjaxService
-->
dwrController
<!-- really basic page -->
dwrController
<!-- index shows the classes which are dwr-enabled -->
<!-- this will no doubt conflict with your /servlet/index.html file -->
dwrController
[/code]
集成后的DWR.xml文件配置与原始的文件配置是有很大差别的
比如这个
[code="xml"]
/dwr:remote
[/code]
与以往的就不一样了
[code="xml"]
[/code]
你可以参考这篇官方文档支集成DWR与SPRING
http://directwebremoting.org/dwr/server/integration/spring.html
简单的dwr与SPRING整合,则DWR是没法用SPRING的注入的BEAN的。。
上面可能不对。
dwr/interface/aclManager.js
你这是相对地址,
你放到文件夹下,这些地址也改了吗?
还有一种可能
JavaScript出现“XXX is not a function”的错误
在DWR框架下调用了class中的一个方法。在dwr.xml文件中吧这个class声明为topicSearch。但是在调用的这个js中也有一个function的名字叫topicSearch。这样就形成了冲突。解决方法很简单,只要修改function的名字即可。
其实这是个前台的JS问题。只要注意到命名即可。
同时,如果不同页面中引用的不同js文件里有相同名字的全局变量,也会出现值的错误。因为在Web网页所包含的任何JavaScript中的任何地方都可以访问全局变量,无论JS是直接嵌入到页面中的还是从JavaScript库中引入的。
试试把这个函数名改改
依然是js路径的错误,输入http://localhost:8080/[YOUR-WEBAPP]/dwr/ 查看js路径。