1.在页面的<script type="text/JavaScript" >内加入
//无刷新请求的xmlhttp请求
var http_request=false;
function createRequest(url)
{
http_request = false;
if (window.XMLHttpRequest) { // Mozilla, Safari,...
http_request = new XMLHttpRequest();
if (http_request.overrideMimeType) {
http_request.overrideMimeType('text/html');
}
} else if (window.ActiveXObject) { // IE
try {
http_request = new ActiveXObject("Msxml2.XMLHTTP");
} catch (e) {
try {
http_request = new ActiveXObject("Microsoft.XMLHTTP");
} catch (e) {}
}
}
if (!http_request) {
alert('不能创建XMLHTTP实例!');
return false;
}
http_request.onreadystatechange=alertContents;
http_request.open("POST",url,true);
http_request.send(null);
}
2.调用--在js调用请求【CONTROL为servlet配置的url-mapping,传参跟一般url传参一样】
createRequest('CONTROL'+'?cmd=listen');
3.在servlet中处理【中文乱码问题】
PrintWriter out;
response.setContentType("html/text");//此5行必备,用于输出中文,否则乱码
response.setCharacterEncoding("UTF-8");
response.setHeader("Cache-Control","no-cache");
out=response.getWriter();
out.println("对不起,系统忙,请稍后再试!"); //为返回的响应结果,在页面直接以alert()显示
华山资源网 Design By www.eoogi.com
广告合作:本站广告合作请联系QQ:858582 申请时备注:广告合作(否则不回)
免责声明:本站资源来自互联网收集,仅供用于学习和交流,请遵循相关法律法规,本站一切资源不代表本站立场,如有侵权、后门、不妥请联系本站删除!
华山资源网 Design By www.eoogi.com