67,538
社区成员
发帖
与我相关
我的任务
分享
<%@ page contentType="text/html; charset=gbk" language="java" import="java.util.*" %>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title>My JSP 'index.jsp' starting page</title>
<script type="text/javascript">
var xmlhttp;
function createHttpRequest()
{
if(window.ActiveXObject)
{
xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
}
else if(window.XMLHttpRequest)
{
xmlhttp=new XMLHttpRequest();
}
}
function asd()
{
createHttpRequest();
xmlhttp.onreadystatechange=handechange;
xmlhttp.open("post","Test");
xmlhttp.send("action=a");
}
function handechange()
{
if(xmlhttp.readyState==4)
{
if(xmlhttp.status==200)
{
var property=null;
var result=xmlhttp.responseXML;
var zcqs= result.getElementsByTagName("zcqzcq");
for(var i=0;i<zcqs.length;i++)
{
property=zcqs[i];
var zcq1=property.getElementsByTagName('zcq')[0].firstChild.nodeValue;
table(zcq1);
document.getElementById('sp').innerHTML=" <font color='#00FF66'>加载成功</font> "
}
}
}
else
{
document.getElementById('sp').innerHTML="<font color='red'>加载中</font>"
}
}
function table(txt)
{
var tb=document.getElementById('tb');
tb.setAttribute('border','1');
var tr=document.createElement('tr');
var td=document.createElement('td');
var tn=document.createTextNode(txt);
td.appendChild(tn);
tr.aapendChild(td);
tb.appendChild(tr);
}
</script>
</head>
<body>
<input type="text" id="zcq" name="name" />
<input type="text" id="un" name="name" />
<input type="button" value="dianji" onclick="asd()" />
<span id="sp"></span>
<span id="aaa"></span>
<table id="tb" >
</table>
</body>
</html>
package com.zcq.Servlet;
import java.io.IOException;
import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.hibernate.Query;
import org.hibernate.Session;
import com.zcq.dao.Asdas;
import com.zcq.dao.Dao;
public class Test extends HttpServlet {
/**
* Constructor of the object.
*/
public Test() {
super();
}
/**
* Destruction of the servlet. <br>
*/
public void destroy() {
super.destroy(); // Just puts "destroy" string in log
// Put your code here
}
/**
* The doGet method of the servlet. <br>
*
* This method is called when a form has its tag value method equals to get.
*
* @param request the request send by the client to the server
* @param response the response send by the server to the client
* @throws ServletException if an error occurred
* @throws IOException if an error occurred
*/
public void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
PrintWriter out = response.getWriter();
response.setContentType("text/xml;charset=gbk");
Dao dao=new Dao();
Session session=dao.session;
Query q=session.createQuery("from Asdas ");
List list=q.list();
StringBuffer buff=new StringBuffer("<b>");
for (Iterator iterator = list.iterator(); iterator.hasNext();) {
Asdas a= (Asdas) iterator.next();
buff.append("<zcqzcq>");
buff.append("<zcq>");
buff.append(a.getZcq());
buff.append("</zcq>");
buff.append("</zcqzcq>");
}
buff.append("</b>");
dao.closeSession();
out.println(buff.toString());
out.flush();
out.close();
}
/**
* The doPost method of the servlet. <br>
*
* This method is called when a form has its tag value method equals to post.
*
* @param request the request send by the client to the server
* @param response the response send by the server to the client
* @throws ServletException if an error occurred
* @throws IOException if an error occurred
*/
public void doPost(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
doGet(request, response);
}
/**
* Initialization of the servlet. <br>
*
* @throws ServletException if an error occurs
*/
public void init() throws ServletException {
// Put your code here
}
}
tr.aapendChild(td); tr.appendChild(td);