大家好,打扰下大家哈。。 小弟有个地方不明白了.就是我用AJAX来提交页面上输入框的值,不用表单(form)。但是Action中的user始终获得不到值。在Action 中式这样这写的 public class userinfoActon extends ActionSupport{
Userinfo user; //提供get和set方法
......
Public String execute(){
consumebiz.getResult(user);
return SUccess;
}jsp页面是这样写的
<input type="test" name="user.username"/>
<input type="passsword" name="user.password"/>}在ajax这样写的if (window.ActiveXObject) {
xmlReq = new ActiveXObject("Microsoft.XMLHTTP");
} else {
xmlReq = new XMLHttpRequest();
}
if (xmlReq) {
xmlReq.open("post", "getres.action, true);
xmlReq.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
xmlReq.onreadystatechange = callback;
xmlReq.send(null);
}不知道该怎么解决,请大家帮忙哈..谢谢了
Userinfo user; //提供get和set方法
......
Public String execute(){
consumebiz.getResult(user);
return SUccess;
}jsp页面是这样写的
<input type="test" name="user.username"/>
<input type="passsword" name="user.password"/>}在ajax这样写的if (window.ActiveXObject) {
xmlReq = new ActiveXObject("Microsoft.XMLHTTP");
} else {
xmlReq = new XMLHttpRequest();
}
if (xmlReq) {
xmlReq.open("post", "getres.action, true);
xmlReq.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
xmlReq.onreadystatechange = callback;
xmlReq.send(null);
}不知道该怎么解决,请大家帮忙哈..谢谢了
<input type="passsword" name="user.password"/>貌似记得name里面的值不能这样子写,要么就直接写上username,不能用XX.xxxx之类的表示、
<input type="test" name="username"/>
<input type="passsword" name="password"/>
你是想直接将标签的name属性命名为你javabean的一个对象属性值中?这样没得到值么?
<input type="passsword" name="password"/>xmlReq.send("username="+document.getElementById("username").value+"&password="+document.getElementById("password").value);
然后在action中添加username和password的set get方法即可
明白了底层的js怎么写后建议你用jquery框架写ajax,如果只为表单验证可以用jquery.validation.js,十分简化
谢谢。。我不是在做验证,是在做那个多条件查询..你说说的那个$.ajax提交数据到后台到底是怎么弄的,能不能给个实例看看啊?谢谢了..