var xmlHttp;
function createXMLHttpRequest(){
if(window.ActiveXObject){
xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
}
else if(window.XMLHttpRequest){
xmlHttp=new XMLHttpRequest();
}
}
function startRequest(){
createXMLHttpRequest();
xmlHttp.open("GET","show.do?id="+document.getElementById("showtext").value,true);
xmlHttp.onreadystatechange=callback;
xmlHttp.send(null);
}
function callback(){
if(xmlHttp.readyState==4){
if(xmlHttp.status==200){
oDiv.innerHTML=xmlHttp.responseText;
}
}
}
ACTION:
response.setContentType("text/xml");
String id=request.getParameter("id");
OpenItems items=new OpenItems();
Information info=(Information)items.QueryInformationById(Integer.parseInt(id));
try {
PrintWriter out=response.getWriter();
out.println("<table>");
out.println("<tr>");
out.println("<td>"+info.getName()+"</td>");
out.println("<td>"+info.getAge()+"</td>");
out.println("<td>"+info.getAddress()+"</td>");
out.println("</tr>");
out.println("</table>");
out.close();
} catch (IOException e) {
// TODO 自动生成 catch 块
e.printStackTrace();
}
return null;
m:
Session session=HibernateSessionFactory.getSession();
Information info=(Information)session.load(Information.class, id);
session.close();
return info;
<script type="text/javascript" src="show.js"></script>
<link href="show.css" rel="stylesheet" type="text/css" />
</head>
<body>
<input type="text" id="showtext"/>
<input type="button" value="click" οnclick="startRequest();"/>
<div id="oDiv"></div>