标题:请教一个页面自动刷新的问题
只看楼主
hwj20070118
Rank: 1
等 级:新手上路
帖 子:94
专家分:0
注 册:2007-1-18
 问题点数:0 回复次数:1 
请教一个页面自动刷新的问题

三个部分组成:
1,我的JSP代码:
<%@ page contentType="text/html; charset=gb2312" language="java" %>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<title>无标题文档</title>
<script language="javascript">
var http_request=false;
function createXMLHttpRequest()
{
if(window.XMLHttpRequest)
{
http_request=new XMLHttpRequest();
}
else if(window.ActiveXObject)
{
try{
http_request=new ActiveXObject("Msxml2.XMLHTTP");
}catch(e)
{
try{
http_request=new ActiveXObject("Microsoft.XMLHTTP");
}catch(e){}
}
}
}

function sendRequest()
{
createXMLHttpRequest();
var url="refresh";
http_request.open("GET",url,true);
http_request.onreadystatechange=processRequest;
http_request.send(null);
}

function processRequest()
{
if(http_request.readystate==4)
{
if(http_request.status==200)
{
display();
setTimeout("display()",1000);
}
else
{alert("出错了!");}
}
}

function display()
{
var name=http_request.responseXML.getElementByTagName("name")[0].firstChild.nodeValue;
var num=http_request.responseXML.getElementByTagName("num")[0].firstChild.nodeValue;
document.getElementById("product").innerHTML=name;
document.getElementById("count").innerHTML=num;
}

</script>

</head>

<body onload="sendRequest()">
<table width="257" height="81" border="0" cellpadding="0" cellspacing="0">
<tr>
<td colspan=2><div align="center">正在热卖的笔记本</div></td>
</tr>
<tr>
<td>型号</td>
<td id="product"></td>
</tr>
<tr>
<td>销售数量</td>
<td id="count"></td>
</tr>
</table>
</body>
</html>



2,我的servlet代码:
import java.io.*;
import javax.servlet.*;
import javax.servlet.http.*;

public class servlet extends HttpServlet
{
public void doGet(HttpServletRequest req,HttpServletResponse resp) throws IOException,ServletException
{
resp.setContentType("text/xml;charset=UTF-8");
resp.setHeader("Cache-Control","no-cache");
PrintWriter out=resp.getWriter();
out.println("<response>");
out.println("<name>IBM</name>");
out.println("<num>160</num>");
out.println("</response>");
}
}



3,我的web.xml配置:
<?xml version="1.0" encoding="ISO-8859-1"?>

<web-app xmlns="http://java.sun.com/xml/ns/j2ee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee web-app_2_4.xsd"
version="2.4">

<display-name>Welcome to Tomcat</display-name>
<description>
Welcome to Tomcat
</description>

<servlet>
<servlet-name>a</servlet-name>
<servlet-class>servlet</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>a</servlet-name>
<url-pattern>/refresh</url-pattern>
</servlet-mapping>
</web-app>



请大家,看一下,哪里出错了.谢谢.

搜索更多相关主题的帖子: dtd loose 页面 charset 
2007-04-28 13:14
hwj20070118
Rank: 1
等 级:新手上路
帖 子:94
专家分:0
注 册:2007-1-18
得分:0 

哈哈.自己顶一下.终于自己知道哪里出错了.

2007-04-30 09:42



参与讨论请移步原网站贴子:https://bbs.bccn.net/thread-135654-1-1.html




关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.072969 second(s), 7 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved