类:
List list = td.findByCriQuety(tb);
response.setContentType("text/xml; charset=UTF-8"); //设置编码格式
response.setHeader("Cache-Control","no-cache");
PrintWriter out;
try {
out = response.getWriter();
out.println("<response>");
for(int i=0;i<list.size();i++)
{
tb=(TempAddressbook) list.get(i);
out.println("<row><col>"+tb.getSname()+"</col><col>"+tb.getAge()+"</col><col>"+
tb.getSex()+"</col><col>"+tb.getBirth()+"</col><col>"+tb.getTel()+
"</col><col>"+tb.getPhon()+"</col><rowid>"+tb.getSid()+"</rowid></row>");
//out.println("<rowid>"+tb.getSid()+"</rowid>");
//<row> <col></col><col></col></row>
}
out.println("</response>");
out.close();//关闭输出流
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
脚本:
var XMLHttpReq;
function send_info(url)
{
createXMLHttpRequest();
var url=url;
XMLHttpReq.onreadystatechange = processRequest;
XMLHttpReq.open("post",url,false);
XMLHttpReq.send(null);
}
function createXMLHttpRequest()
{
if(window.XMLHttpRequest)
{
XMLHttpReq=new XMLHttpRequest();
}else if(window.ActiveXObject)
{
try{
XMLHttpReq=new ActiveXObject("Msxml2.XMLHTTP");
}catch(e)
{
try{
XMLHttpReq=new ActiveXObject("Microsoft.XMLHTTP");
}catch(e){}
}
}
}
function processRequest()
{
if(XMLHttpReq.readyState == 4)
{
if(XMLHttpReq.status == 200)
{
/*
以下语句用于获取如下xml格式文件 <row><col></col></row>
使用DOM方法生成页面 delDis 方法为删除页面原来数据
*/
var rows = XMLHttpReq.responseXML.getElementsByTagName("row");
var tableinfo=document.getElementById("info");
delDis(tableinfo);
for(var i=0;i<rows.length;i++)
{
var cols=rows[i].getElementsByTagName("col");
var tr= document.createElement("<tr>");
var checkbox = document.createElement("input");
var sid = rows[i].getElementsByTagName("rowid")[0].firstChild.data; //获取某一节点值
checkbox.type="checkbox";
checkbox.name="checkbox";
checkbox.value=sid;
checkbox.id="checkbox";
var firsttd = document.createElement("<td>");
firsttd.align="center";
firsttd.appendChild(checkbox);
tr.appendChild(firsttd);
for(var j=0;j<cols.length;j++)
{
var col="col"+j;
col=cols[j].firstChild.data;
if(col=="null")
col = " ";
var td= document.createElement("<td>");
td.align="right";
var textinfo=document.createTextNode(col);
td.appendChild(textinfo);
tr.appendChild(td);
}
tableinfo.appendChild(tr); //展示在<tbody id="info"></tbody>的地方
}
}
}
}
function delDis(tableinfo)
{
var tablen = tableinfo.childNodes.length;
for(var n=tablen-1;n>=0;n--)
{
//tableinfo.removeChild(tableinfo.childNodes[n]);
tableinfo.deleteRow(n);
}
}
function checksum() //复选框的全部选中
{
var checkedvalue="";
var distb = document.getElementById("distr").style.display;
var sumsid = document.getElementsByName("sumsid")[0].checked;
if(distb=="block")
{
checkedvalue = document.getElementsByName("sid");
}else
{
checkedvalue = document.getElementsByName("checkbox");
}
for(var i=0;i<checkedvalue.length;i++)
{
checkedvalue[i].checked=sumsid;
}
}
List list = td.findByCriQuety(tb);
response.setContentType("text/xml; charset=UTF-8"); //设置编码格式
response.setHeader("Cache-Control","no-cache");
PrintWriter out;
try {
out = response.getWriter();
out.println("<response>");
for(int i=0;i<list.size();i++)
{
tb=(TempAddressbook) list.get(i);
out.println("<row><col>"+tb.getSname()+"</col><col>"+tb.getAge()+"</col><col>"+
tb.getSex()+"</col><col>"+tb.getBirth()+"</col><col>"+tb.getTel()+
"</col><col>"+tb.getPhon()+"</col><rowid>"+tb.getSid()+"</rowid></row>");
//out.println("<rowid>"+tb.getSid()+"</rowid>");
//<row> <col></col><col></col></row>
}
out.println("</response>");
out.close();//关闭输出流
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
脚本:
var XMLHttpReq;
function send_info(url)
{
createXMLHttpRequest();
var url=url;
XMLHttpReq.onreadystatechange = processRequest;
XMLHttpReq.open("post",url,false);
XMLHttpReq.send(null);
}
function createXMLHttpRequest()
{
if(window.XMLHttpRequest)
{
XMLHttpReq=new XMLHttpRequest();
}else if(window.ActiveXObject)
{
try{
XMLHttpReq=new ActiveXObject("Msxml2.XMLHTTP");
}catch(e)
{
try{
XMLHttpReq=new ActiveXObject("Microsoft.XMLHTTP");
}catch(e){}
}
}
}
function processRequest()
{
if(XMLHttpReq.readyState == 4)
{
if(XMLHttpReq.status == 200)
{
/*
以下语句用于获取如下xml格式文件 <row><col></col></row>
使用DOM方法生成页面 delDis 方法为删除页面原来数据
*/
var rows = XMLHttpReq.responseXML.getElementsByTagName("row");
var tableinfo=document.getElementById("info");
delDis(tableinfo);
for(var i=0;i<rows.length;i++)
{
var cols=rows[i].getElementsByTagName("col");
var tr= document.createElement("<tr>");
var checkbox = document.createElement("input");
var sid = rows[i].getElementsByTagName("rowid")[0].firstChild.data; //获取某一节点值
checkbox.type="checkbox";
checkbox.name="checkbox";
checkbox.value=sid;
checkbox.id="checkbox";
var firsttd = document.createElement("<td>");
firsttd.align="center";
firsttd.appendChild(checkbox);
tr.appendChild(firsttd);
for(var j=0;j<cols.length;j++)
{
var col="col"+j;
col=cols[j].firstChild.data;
if(col=="null")
col = " ";
var td= document.createElement("<td>");
td.align="right";
var textinfo=document.createTextNode(col);
td.appendChild(textinfo);
tr.appendChild(td);
}
tableinfo.appendChild(tr); //展示在<tbody id="info"></tbody>的地方
}
}
}
}
function delDis(tableinfo)
{
var tablen = tableinfo.childNodes.length;
for(var n=tablen-1;n>=0;n--)
{
//tableinfo.removeChild(tableinfo.childNodes[n]);
tableinfo.deleteRow(n);
}
}
function checksum() //复选框的全部选中
{
var checkedvalue="";
var distb = document.getElementById("distr").style.display;
var sumsid = document.getElementsByName("sumsid")[0].checked;
if(distb=="block")
{
checkedvalue = document.getElementsByName("sid");
}else
{
checkedvalue = document.getElementsByName("checkbox");
}
for(var i=0;i<checkedvalue.length;i++)
{
checkedvalue[i].checked=sumsid;
}
}