ajax提交数据到Struts2中的Action

Allanheqing Allanheqing 墨衍会员 · AI 创作全网分发 墨衍智能分发 通过墨衍一键同步至各平台 可同步平台 CSDN微信公众号微博知乎掘金百家号博客园抖音小红书 你的文章也可以这样分发 墨衍会员 ¥399起/年,写一次发全网 我也要 + 加入社区
大家好,打扰下大家哈。。

小弟有个地方不明白了.就是我用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);
}

不知道该怎么解决,请大家帮忙哈..谢谢了
...全文
评论 15
收藏 已收藏
分享
返回顶部
Allanheqing
Web 开发 81,108 成员 341,721 内容