日期:2014-05-16 浏览次数:20640 次
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<title>Login</title>
</head>
<script type="text/javascript">
var http_request = false;
function send_request(url) {//初始化、指定处理函数、发送请求的函数
http_request = false;
file://开始初始化XMLHttpRequest对象
if(window.XMLHttpRequest) {
…………………………此处省略ajax代码
if (!http_request) { // 异常,创建对象实例失败
window.alert("不能创建XMLHttpRequest对象实例.");
return false;
}
http_request.onreadystatechange = processRequest;
// request.setCharacterEncoding("utf-8");
// 确定发送请求的方式和URL以及是否同步执行下段代码
http_request.open("GET", url, true);
http_request.send();
}
// 处理返回信息的函数
function processRequest() {
if (http_request.readyState == 4) { // 判断对象状态
if (http_request.status == 200) { // 信息已经成功返回,开始处理信息
result.innerHTML=http_request.responseText;
} else { //页面不正常
alert("您所请求的页面有异常。");
}
}
}
</script>
<body>
<form>
<input type="button" value="提交" onclick="send_request('mouservlet');"/>
</form>
<div id="result"> </div>
</body>
</html>
PrintWriter out=response.getWriter();
response.setContentType("text/html;charset=gb2312");
//request.setCharacterEncoding("gb2312");
response.setHeader("Pragma","No-cache");
response.setDateHeader("Expires", 0);
response.setHeader("Cache-Control","No-cache");
String str="欢迎你!";
out.println(str);
out.close();