ajax提交数据到Struts2中的Action
大家好,打扰下大家哈。。
小弟有个地方不明白了.就是我用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);
}
不知道该怎么解决,请大家帮忙哈..谢谢了
小弟有个地方不明白了.就是我用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);
}
不知道该怎么解决,请大家帮忙哈..谢谢了
...全文
相关推荐
Struts2和Ajax数据交互示例详解
主要给大家介绍了关于Struts2和Ajax数据交互的相关资料,文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,需要的朋友们下面随着小编来一起学习学习吧。
Struts2中实现Ajax技术的全面指南
本文还有配套的精品资源,点击获取 简介:Struts2是一个Java Web框架,支持MVC架构,而Ajax技术能够实现无刷新页面交互,提升用户体验。本文将指导如何在Struts2框架中集成和应用Ajax技术,包括理解Struts2工作原理、通过引入jQuery库简化Ajax使用、创建和配置处理Ajax请求的Action类,以及通过配置文件和回调函数处理Ajax响应。同时,...
struts2 + jquery +ajax 登录验证
struts2 + jquery +ajax 登录验证
Struts2 Ajax
Struts 2 ajax example
Struts2+Ajax实现的用户登录
Struts2+Ajax实现的用户登录 Struts2 Ajax Sprint Hibernate


Web 开发
