读书人

ajax传参有关问题jsp页面可以接受

发布时间: 2013-09-11 16:26:28 作者: rapoo

ajax传参问题,jsp页面可以接受,sturts2不行
ajax代码:


<script type="text/javascript">
function ajaxSubmit()
{
//创建XMLHttpRequest对象
var xmlhttp
try{
xmlhttp = new XMLHttpRequest();
}catch(e)
{
xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
}
//创建请求结果处理程序
xmlhttp.onreadystatechange = function()
{
if(4 == xmlhttp.readyState)
{
if(200 == xmlhttp.status)
{
var date = xmlhttp.responseText;
Handling(date);
}else{
alert("error");
}
}
}
//打开连接,true代表异步提交
xmlhttp.open("get","luser.action?model=learnpace",true);
//当方法为POST时需要设置HTTP头
//xmlhttp.setRequestHeader('Content-Type','application/x-www-form-urlencoded');
//当方法为POST时需要发送数据
//xmlhttp.send("model=learnpace");
}

function openwin()
{
if(window.confirm('请点击确定传参'))
{
ajaxSubmit();
return true;
}else{
return false;
}
}
</script>


首先我确认struts没有配置错,页面存在路径正确,通过这种方法传参,luser.action接受不到model的值,什么都没有,我另直接写了个2.jsp页面测试成功

<%
String model = request.getParameter("model");
System.out.println("model:" + model);
%>


请问问题可能出在哪里? ajax struts java 异步 传参
[解决办法]
你确认jsp能接收。。?你都没有发送请求。。

//打开连接,true代表异步提交
xmlhttp.open("get","luser.action?model=learnpace&_dc="+new Date().getTime(),true);//放置IE get缓存
//当方法为POST时需要设置HTTP头
//xmlhttp.setRequestHeader('Content-Type','application/x-www-form-urlencoded');
//当方法为POST时需要发送数据
//xmlhttp.send("model=learnpace");



xmlhttp.send(null)

读书人网 >Ajax

热点推荐