<%@ page language="java" import="java.util.*" pageEncoding="utf-8"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>
<!
DOCTYPE
HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<
html
>
head
>
base
href="<%=basePath%>">
title
>My JSP 'index.jsp' starting page</
>
meta
http-equiv="pragma" content="no-cache">
http-equiv="cache-control" content="no-cache">
http-equiv="expires" content="0">
http-equiv="keywords" content="keyword1,keyword2,keyword3">
http-equiv="description" content="This is my page">
<link rel="stylesheet" type="text/css" href="styles.css">
-->
</
>
script
type="text/javascript">
var xmlHttprequest = null;
function ajax(){
if(window.ActiveXObject){
xmlHttprequest = new ActiveXObject("Microsoft.XMLHTTP");
}else if(window.XMLHttpRequest){
xmlHttprequest = new XMLHttpRequest;
}
if(xmlHttprequest != null){
var v1 = document.getElementById("v1").value;
var v2 = document.getElementById("v2").value;
xmlHttprequest.open("post","ajaxServlet.do",true);
xmlHttprequest.onreadystatechange=ajaxCallBack;
xmlHttprequest.setRequestHeader("Content-type",
"application/x-www-form-urlencoded");
xmlHttprequest.send("v1="+v1+"&v2="+v2);
}
}
function ajaxCallBack(){
if(xmlHttprequest.readyState == 4){
if(xmlHttprequest.status == 200){
var responseText = xmlHttprequest.responseText;
document.getElementById("div").innerHTML = responseText;
}
}else{
document.getElementById("div").innerHTML="服务器出现错误!";
}
}
>
body
>
input
type="button" value="click here" onclick="ajax();" />
type="text" id="v1"></
>
type="text" id="v2"></
>
div
id="div"></
>
>
>