=============jsp中的javaScript=====================================
<%--向后臺發(fā)送相應(yīng)的信息--%>
function sendUrl(val,method,check){
var param1 = document.all("param1").value;
//指定請求發(fā)送的URL地址和參數(shù)
var url="/test.do?method=list¶m1="+param1;
if(window.XMLHttpRequest){
req=new XMLHttpRequest();
}
else if (window.ActiveXObject){
req = new ActiveXObject("Microsoft.XMLHTTP");
}
if(req){
req.open("GET",url,true);//向服務(wù)器發(fā)送請求
req.onreadystatechange=callback;//指定回調(diào)函數(shù)
req.send(null);
}
}
function callback() //回調(diào)函數(shù)
{
if(req.readyState==4)//判斷接受到的響應(yīng)狀態(tài),如果是4表示加載完畢
{
if(req.status==200){
parseMessage();//收到服務(wù)器數(shù)據(jù)后進(jìn)行解析
}else{
alert("該結(jié)算戶不存在!");
}
}else { //響應(yīng)未加載成功,頁面中的代碼
//document.getElementById("check_userbh").innerHTML="<font color=\"red\">" + "正在查詢用戶信息..." + "</font>";
//document.getElementById("check_userbh").innerHTML="<img src=\"images/loading.gif\" width=\"103\" height=\"20\">";
}
}
//對返回數(shù)據(jù)進(jìn)行解析
function parseMessage(){
var xmlDoc =req.responseText;
var form = document.forms[0];
if(xmlDoc.length==0){
return;
}else{
//alert(xmlDoc);
}
}
=================================java===========
try{
//設(shè)置返回內(nèi)容類型
response.setContentType("text/xml;charset=GBK");
//設(shè)置不緩存
response.setHeader("Cache-Control","no-cache");
//用流輸出到頁面.
response.getWriter().write(strData);=====>strData返回前臺的數(shù)據(jù)
return null;
} catch (Exception e) {
request.setAttribute("Exception", e);
return null;
}