浏览 210 次
|
精华帖 (0) :: 良好帖 (0) :: 新手帖 (0) :: 隐藏帖 (0)
|
|
|---|---|
| 作者 | 正文 |
|
时间:2008-04-13
返回Collection和Void的方法都能很好的暴露到客户端,为什么返回String的方法就不行了?
声明:JavaEye文章版权属于作者,受法律保护。没有作者书面许可不得转载。
|
|
| 返回顶楼 | |
|
时间:2008-04-14
lxl686 写道 返回Collection和Void的方法都能很好的暴露到客户端,为什么返回String的方法就不行了?
怎么不行?比如说这样一个JAVA方法:
public String sayHello(String name) {
return "Hello " + name;
}
将这个方法通过DWR暴露给WEB,在WEB的JS中,比如说为sayHello.js,则在WEB中只需要这样调用:
sayHello.sayHello(document.getElementById("inputName").value, function(returnData) { //这里的function()是回//调方法
alert(returnData);
})
你试试看,看能不能返回。呵呵,看来我今天心情不错啊,这个都回复。 |
|
| 返回顶楼 | |
|
时间:2008-04-14
不行啊,我头开始疼了.就上面单个例子来说,能正常显示;可我的咋就不行了啊..
在PersonBusinessImpl类中定义的一个方法:去检查用户名是否已经存在
public String checkPersonUserName(String personUserName) throws Person_LogonException {
PersonInfo pi = null;
try {
pi = (PersonInfo) personInfoDAO
.findByPersonUserName(personUserName).get(0);
} catch (IndexOutOfBoundsException ex) {
return "no";
}
return "yes";
}
在一个personRegist.jsp里: <html:text property="personUserName" onblur="checkPersonUserName(this.value);"/> 在js文件里:
function isHasPerson() {
document.getElementById("noUserError").innerHTML = "检查中...";
var userName = document.getElementsByName("personUserName");
js_person.checkPersonUserName(userName[0].value, isHasPersonTwo);
}
function isHasPersonTwo(date) {
var n = document.getElementById("noUserError");
if (date == 'no') {
n.innerHTML = "该用户名可用!";
} else if(date == 'yes'){
n.innerHTML = "用户名已存在!";
} else{
n.innerHTML = "";
}
}
在dwr.xml里
<dwr>
<allow>
<create creator="spring" javascript="js_person">
<param name="beanName" value="personBusiness"/>
</create>
</allow>
</dwr>
spring里也有这个bean了. 可它咋就不行了呢? |
|
| 返回顶楼 | |




