请教一个页面自动刷新的问题
<P>三个部分组成:<BR>1,我的JSP代码:<BR><%@ page contentType="text/html; charset=gb2312" language="java" %><BR><!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "<a href="http://www.w3.org/TR/html4/loose.dtd" target="_blank" >http://www.w3.org/TR/html4/loose.dtd</A>"><BR><html><BR><head><BR><meta http-equiv="Content-Type" content="text/html; charset=gb2312"><BR><title>无标题文档</title><BR><script language="javascript"><BR>var http_request=false;<BR>function createXMLHttpRequest() <BR>{<BR> if(window.XMLHttpRequest)<BR> {<BR> http_request=new XMLHttpRequest();<BR> }<BR> else if(window.ActiveXObject)<BR> {<BR> try{<BR> http_request=new ActiveXObject("Msxml2.XMLHTTP"); <BR> }catch(e)<BR> {<BR> try{<BR> http_request=new ActiveXObject("Microsoft.XMLHTTP");<BR> }catch(e){}<BR> }<BR> }<BR>}</P><P>function sendRequest() <BR>{<BR> createXMLHttpRequest();<BR> var url="refresh";<BR> http_request.open("GET",url,true);<BR> http_request.onreadystatechange=processRequest;<BR> http_request.send(null);<BR>}</P>
<P>function processRequest() <BR>{<BR> if(http_request.readystate==4)<BR> {<BR> if(http_request.status==200)<BR> {<BR> display();<BR> setTimeout("display()",1000);<BR> }<BR> else<BR> {alert("出错了!");}<BR> }<BR>}</P>
<P>function display()<BR>{<BR> var name=http_request.responseXML.getElementByTagName("name")[0].firstChild.nodeValue;<BR> var num=http_request.responseXML.getElementByTagName("num")[0].firstChild.nodeValue;<BR> document.getElementById("product").innerHTML=name;<BR> document.getElementById("count").innerHTML=num;<BR>}</P>
<P></script></P>
<P></head></P>
<P><body onload="sendRequest()"><BR><table width="257" height="81" border="0" cellpadding="0" cellspacing="0"><BR> <tr><BR> <td colspan=2><div align="center">正在热卖的笔记本</div></td><BR> </tr><BR> <tr><BR> <td>型号</td><BR> <td id="product"></td><BR> </tr><BR> <tr><BR> <td>销售数量</td><BR> <td id="count"></td><BR> </tr><BR></table><BR></body><BR></html><BR><BR><BR><BR>2,我的servlet代码:<BR>import java.io.*;<BR>import javax.servlet.*;<BR>import javax.servlet.http.*;</P>
<P>public class servlet extends HttpServlet<BR>{<BR> public void doGet(HttpServletRequest req,HttpServletResponse resp) throws IOException,ServletException<BR> {<BR> resp.setContentType("text/xml;charset=UTF-8");<BR> resp.setHeader("Cache-Control","no-cache");<BR> PrintWriter out=resp.getWriter();<BR> out.println("<response>");<BR> out.println("<name>IBM</name>");<BR> out.println("<num>160</num>");<BR> out.println("</response>");<BR> }<BR>}<BR><BR><BR><BR>3,我的web.xml配置:<BR><?xml version="1.0" encoding="ISO-8859-1"?></P>
<P><web-app xmlns="<a href="http://java.sun.com/xml/ns/j2ee" target="_blank" >http://java.sun.com/xml/ns/j2ee</A>"<BR> xmlns:xsi="<a href="http://www.w3.org/2001/XMLSchema-instance" target="_blank" >http://www.w3.org/2001/XMLSchema-instance</A>"<BR> xsi:schemaLocation="<a href="http://java.sun.com/xml/ns/j2ee" target="_blank" >http://java.sun.com/xml/ns/j2ee</A> web-app_2_4.xsd"<BR> version="2.4"></P>
<P> <display-name>Welcome to Tomcat</display-name><BR> <description><BR> Welcome to Tomcat<BR> </description><BR> <BR> <servlet><BR> <servlet-name>a</servlet-name><BR> <servlet-class>servlet</servlet-class><BR> </servlet><BR> <servlet-mapping><BR> <servlet-name>a</servlet-name><BR> <url-pattern>/refresh</url-pattern> <BR> </servlet-mapping><BR></web-app><BR><BR><BR><BR>请大家,看一下,哪里出错了.谢谢.<BR></P> <P>哈哈.自己顶一下.终于自己知道哪里出错了.</P>
页:
[1]
