解决方法是关闭response的writer。
下面是ajax代码
$j.ajax({
type : "POST",
url : "/asi/jsonCarrier.jsp",
data : {"artistId":"${artistID}"}, //这里从session里拿出了artistID变量,用的是el表达式
datatype : "text",
timeout: 10000,
success : function(data) {
if (data!="" && data!=null){
var dataArr = data;
var jsonData = dataArr.statistics;
var priceData = [];
var volumeData = [];
var summaryData = [];
$j.each(jsonData, function(i, dataItem) {
priceData[i] = [ i, dataItem.beta ];
volumeData[i] = [ i, dataItem.volume ];
summaryData[i] = [ i, dataItem.volatility ];
});
$j("#artistName").html(dataArr.meta.artist_forename+" "+dataArr.meta.artist_surname);
displayGraph(jsonData, priceData, volumeData, summaryData);
}
},
error : function(XMLHttpRequest, textStatus, errorThrown){
alert(textStatus);
}
})
下面是 jsonCarrier.jsp里的java代码
<%
String artistId = request.getParameter("artistId");
String jsonData = DBSightXmlUtil.getXmlFromServer("http://aaa.com/json/asi-artist-"+ artistId + "-y.json");
response.setContentType("application/json");
response.getWriter().flush();
response.getWriter().write(jsonData);
response.getWriter().close(); //这里就是关键
%>