var xmlHttp; function sendRequest() { var oForm=document.forms[0]; var sSend="id="+oForm.txtCustomerId.value; xmlHttp=new ActiveXObject("Microsoft.XMLHttp"); xmlHttp.open("post",oForm.action,true); xmlHttp.setRequestHeader("Content-Type","application/x-www-form-urlencoded");
<form action='a.jsp' method='get'>
<input type="text" name="account">
<input type="password" name="password">
<input type="submit" value="提交">
</form>你只能在a.jsp中用request 对象
request.getParameter("account");
request.getParameter("password");
获得value而不能通过js获取。
如果用到了就可以通过设置html:form 的 styleId 来获取值
Struts 的<html:form> 标签比较特殊要取得他的节点,需要用styleId来定义.
例子如下:
<html:form action="/yourAction.do" styleId="deleteForm" method="post" > document.getElementById("deleteForm")来取得! 你先试下,这里的 deleteForm 是Struts的FormBean,当你提交到这个Action时,值会自动填入FormBean中
var xmlHttp;
function sendRequest()
{
var oForm=document.forms[0];
var sSend="id="+oForm.txtCustomerId.value;
xmlHttp=new ActiveXObject("Microsoft.XMLHttp");
xmlHttp.open("post",oForm.action,true);
xmlHttp.setRequestHeader("Content-Type","application/x-www-form-urlencoded");
xmlHttp.onreadystatechange=function()
{
if(xmlHttp.readyState == 4){ if(xmlHttp.status == 200){ document.getElementById("results").innerHTML = xmlHttp.responseText;
}
else {
document.getElementById("results").innerHTML = "error occured";
}
}
}
xmlHttp.send(sSend);
}
</script>
</head>
<body>
<form method="post" action="GetCustomerData.jsp" onsubmit="sendRequest();return false"><input type="text" id="txtCustomerId" name="txtCustomerId"/>
<input type="submit" value="Get Customer Info"/></form>
<div id="results">
</div>
服务器端处理不变,仍用request.getParameter("xxx")服务器不能用javascript获取提交上来的数据。
out.println("alert("+name+")");
out.println("</script>");当然你用servlet处理也是一样的,只不过要分清是post/get,分别运行 doPost/doGet处理
function subClick()
{
//处理代码
document.form1.action="提交的路径"
document.form1.submit();
}
</script>
<form name="form1>
<input type="text" name="f1"><input type="button" value="提交" onclick="subClick">
</form>