Ajax异步调用servlet--注意路径
--------------jsp--
<%@ 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%>">
<script type="text/javascript">
var xmlHttp;
function createXMLHttpRequest()
{
try{
xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
}
catch(e)
{
try{
xmlHttp = new XMLHttpRequest();
}
catch(e)
{
xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
}
}
}
function startRequest()
{
createXMLHttpRequest();
alert("1111");
//var url = "http://localhost:8080/ajax/servlet/ajaxServlet?timestamp="+ new Date().getTime() +"&username=pangbo&password=12345";
var url = "servlet/AjaxServlet?timestamp="+ new Date().getTime() +"&username=pangbo&password=12345";
xmlHttp.open("GET",url,true);
xmlHttp.onreadystatechange = handleXMLHttpRequest;
xmlHttp.send(null);
}
function handleXMLHttpRequest()
{
if(xmlHttp.readyState==4)
{
if(xmlHttp.status==200)
{
document.getElementById("hints").style.color="yellow";