日期:2014-05-20  浏览次数:20941 次

使用dwr,为什么后台java代码执行了,但是前台的js回调函数不执行呢?
dwr.xml 

XML code

<allow>
    <create javascript="CheckCallerNbr" creator="spring">
        <param name="class" value="com.seaway.sh.service.TermManager" />
        <param name="beanName" value="termManager" />
    </create>
</allow>




JAVA方法: 

Java code

public class TermManagerImpl extends GenericManagerImpl<Term, String> implements TermManager {
    TermDao termDao;

    public TermManagerImpl(TermDao termDao) {
        super(termDao);
        this.termDao = termDao;
    }
    
    public String checkCallerNbr(String callerNbr) {
        System.out.println("checkCallerNbr method is execute!");
        System.out.println("callerNbr is : " + callerNbr);
        return "Hello ," + callerNbr;
    }
}



jsp页面: 
HTML code

<head>
    <title><fmt:message key="termDetail.title" />
    </title>
    <meta name="heading" content="<fmt:message key='termDetail.heading'/>" />
    <script src="<c:url value='/dwr/engine.js' />" type="text/javascript"></script>
    <script src="<c:url value='/dwr/util.js' />" type="text/javascript"></script>
    <script src="<c:url value='/dwr/interface/CheckCallerNbr.js' />" type="text/javascript"></script>
    <script src="<c:url value='/scripts/hello.js' />" type="text/javascript"></script>
</head>


<input type="button" onclick="hello();" value="Hello">
<div id="msg"></div>



hello.js 
JScript code

function hello() {
    CheckCallerNbr.checkCallerNbr("spring",callback);
}
    
function callback(data) {
    alert(data);
    DWRUtil.setValue('msg',data);
}




在控制台中已经打印出checkCallerNbr method is execute!和callerNbr is : spring,但是为什么callback函数却没执行呢??

------解决方案--------------------
1.可以看下 <script src =request.getContextPath()/dwr/engine.js' />" type="text/javascript"></script>

js文件是否存在

2.我不知道你怎么拦截dwr请求的.因为对于dwr,,他是不经过controller层的,他调用的直接是Spring bean.

------解决方案--------------------

------解决方案--------------------
帮顶一下!
------解决方案--------------------
帮助