2009年8月14日星期五

DWR错误的解决过程

今天遇到了个错误,解决了很久都没够定。本想求助到mail-list上,但是写信的时候居然发现了原因。只好发到Blog上记录一下。一下是信的内容:

Hi everyone !
         I'm new to DWR. I'm  working on a project using DWR. I met a problem,when I call the server-side code.

Error from firebug:
         anonymous
("Error: undefined, Error", true)engine.js (第 598 行)
         eval()4 (第 4 行)
         anonymous("\r\n//#DWR-INSERT\r\n//#DWR-REPLY\r\ndwr.engine.remote.handleException("1","0",{javaClassName:"java.lang.Throwable",message:"Error"});         \r\n")engine.js (第 545 行)
         anonymous()

Server-side code:
      public class PasswordService {

              public void changePassword(String oldPassword, String newPassword) throws WrongPasswordException{
                     HttpSession session = (WebContextFactory.get()).getSession();
                     // Get user's name
                    String name = ((User)session.getAttribute("user")).getName();

                    if (name !=null && oldPassword != null && newPassword != null) {
                        if (!changePassword(name, oldPassword, newPassword)) {
                           throw new WrongPasswordException();
                        }
                    }
                }
           }

Client-side Javascript code:
        function change() {
            var name = dwr.util.getValue("name");
            var oldpsw = dwr.util.getValue("oldpassword");
            var newpsw = dwr.util.getValue("newpassword");
            Psw.changePassword(name,oldpsw,newpsw);
        }

错误原因:
      Javascript调用PasswordService类的函数Psw.changePassword()的参数与原java函数的方法不匹配。

可怜我整一个下午,都是粗心的惹得祸,修改代码是漏改的结果。

没有评论: