谁有ajax留言板的例子? 谁有ajax留言板的例子? 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 我曾经试图想在静态环境下仅用js&xml实现留言板功能但是好像不是很可能找不到js如何远程操作服务器上的xml文件的方法如果有高手能解决或者有例子就请分享一下啊 AUTHOR:imA(男的不会,会的不男) 写了一个简单的例子,就是前端的一个html页面不断向后台servlet请求,后台servlet每次生成一个随机的long,前台html每次都显示这个long值,你可以找个tomocat服务器部署一下。index.html:<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"><html><head><meta http-equiv="Content-Type" content="text/html; charset=UTF-8"><title>Title</title><script>function Recieve(){if(window.XMLHttpRequest){xmlHttp=new XMLHttpRequest()}else if(window.ActiveXObject){xmlHttp=new ActiveXObject("Microsoft.XMLHTTP")}xmlHttp.onreadystatechange=function(){if((xmlHttp.readystate==4)&&(xmlHttp.status==200)){text=xmlHttp.responseText;document.getElementById("view").value=text;}}xmlHttp.open("POST","/webchat/ViewServlet",true);xmlHttp.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");xmlHttp.send();}window.setInterval("Recieve()",60);//设置定时执行,60是执行间隔,单位是毫秒</script></head><body><input id="view" type="text" readonly="readonly"/></body></html>Servlet.java:package com.servlet;import java.io.IOException;import java.util.Random;import javax.servlet.ServletException;import javax.servlet.http.HttpServletRequest;import javax.servlet.http.HttpServletResponse; public class ViewServlet extends javax.servlet.http.HttpServlet implements javax.servlet.Servlet {public ViewServlet() {super();} protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {doPost(request,response);} protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {Random r=new Random();long l=r.nextLong();response.getWriter().write(""+l);response.getWriter().flush();} }--------------------servlet的映射:<servlet><description></description><display-name>ViewServlet</display-name><servlet-name>ViewServlet</servlet-name><servlet-class>com.servlet.ViewServlet</servlet-class></servlet><servlet-mapping><servlet-name>ViewServlet</servlet-name><url-pattern>/ViewServlet</url-pattern></servlet-mapping>其中在html中的xmlHttp.open("POST","/webchat/ViewServlet",true);中的webchat是我的应用项目的名称,你可以改成你自己的,然后把上面的servlet和html文件部署到你自己的应用上,然后在浏览器中输入访问这个html的地址,可以看到效果。 lurkerxh(lurkerxhxh) 给我发份到邮箱嘛,谢谢[email protected] 如何在自己的filter中获取action的相关信息,对struts2了解的进来 sqlserver2000中的top怎么用在线等,好用马上给分。 向大家请教‘网眼webeye’的实现方法 windows.open("t.html")图片大了显示不出来。 jdbc:odbc桥 tomcat 启动时自动加载servlet配置 急!框架集问题! 给文件加密 jsp运行环境的配置问题 com.ms.activeX包在哪里能找到? 删除文件的问题 关于将用户提交表单的信息另存为word文档的问题
但是好像不是很可能
找不到js如何远程操作服务器上的xml文件的方法
如果有高手能解决
或者有例子就请分享一下啊
写了一个简单的例子,就是前端的一个html页面不断向后台servlet请求,后台servlet每次生成
一个随机的long,前台html每次都显示这个long值,你可以找个tomocat服务器部署一下。
index.html:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Title</title><script>
function Recieve()
{if(window.XMLHttpRequest)
{
xmlHttp=new XMLHttpRequest()
}
else if(window.ActiveXObject)
{
xmlHttp=new ActiveXObject("Microsoft.XMLHTTP")
}
xmlHttp.onreadystatechange=function()
{
if((xmlHttp.readystate==4)&&(xmlHttp.status==200))
{
text=xmlHttp.responseText;
document.getElementById("view").value=text;
}
}
xmlHttp.open("POST","/webchat/ViewServlet",true);
xmlHttp.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
xmlHttp.send();
}
window.setInterval("Recieve()",60);//设置定时执行,60是执行间隔,单位是毫秒
</script></head>
<body>
<input id="view" type="text" readonly="readonly"/>
</body>
</html>Servlet.java:
package com.servlet;import java.io.IOException;
import java.util.Random;import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse; public class ViewServlet extends javax.servlet.http.HttpServlet implements javax.servlet.Servlet {public ViewServlet() {
super();
} protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
doPost(request,response);
} protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
Random r=new Random();
long l=r.nextLong();
response.getWriter().write(""+l);
response.getWriter().flush();
}
}
--------------------
servlet的映射:
<servlet>
<description>
</description>
<display-name>
ViewServlet</display-name>
<servlet-name>ViewServlet</servlet-name>
<servlet-class>
com.servlet.ViewServlet</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>ViewServlet</servlet-name>
<url-pattern>/ViewServlet</url-pattern>
</servlet-mapping>其中在html中的xmlHttp.open("POST","/webchat/ViewServlet",true);
中的webchat是我的应用项目的名称,你可以改成你自己的,然后把上面的servlet和html文件部署
到你自己的应用上,然后在浏览器中输入访问这个html的地址,可以看到效果。
[email protected]