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()显示
标签:
JSP,XMLHttpRequest,动态无刷新

免责声明:本站文章均来自网站采集或用户投稿,网站不提供任何软件下载或自行开发的软件! 如有用户或公司发现本站内容信息存在侵权行为,请邮件告知! 858582#qq.com
桃源资源网 Design By www.nqtax.com