日期:2014-05-16  浏览次数:20784 次

求助。Ajax “请求的页面有异常” - Web 开发 / Ajax
代码如下:
JSP:
function doAjax(){ 按钮点击,触发此方法
  var url = "<%=path%>/caseServlet.do?op=doAjax"; //调用servlet
  if (window.XMLHttpRequest) { 
  req = new XMLHttpRequest(); 
  }else if (window.ActiveXObject) { 
  req = new ActiveXObject("Microsoft.XMLHTTP"); 
  } 
  if(req){ 
  req.open("GET",url, true);  
  req.onreadystatechange = checkcontent; 
  req.send(null); 
  } 
   
}
function checkcontent(){ 
alert(req.readyState);
alert(req.status);
  if (req.readyState == 4 && req.status == 200) { // 判断对象状态 
  // 信息已经成功返回,开始处理信息 
  if(req.responseText != ""){ 
  var arrResult = req.responseText.split("@@@"); //拼接字符串间隔是"@@@"
  alert(req.responseText); 
  document.getElementById('posBp').innerText=arrResult[2]; //把返回值放入指定位置
  }
  else{
  alert('There was a problem with the request.');
  } 
  }
  else {//页面不正常 
  alert("您所请求的页面有异常。"); 
  } 
  } 
Servlet:
protected void doAjax(HttpServletRequest request,HttpServletResponse response) throws ServletException, IOException {
HttpSession session=request.getSession();
if(session.getAttribute("sn")!=null){
RiskBean riskBean=CaseDAO.selectRiskBean(Long.parseLong(session.getAttribute("sn").toString()), "IVCD"); 
PrintWriter pw=response.getWriter();
StringBuffer sb=new StringBuffer();
  String posreduMin=Float.toString(riskBean.getRiskReduMin()); 
String reduMax=Float.toString(riskBean.getRiskReduMax());  
sb.append(reduMin); sb.append("@@@");
sb.append(reduMax); 
pw.write(sb.toString());
pw.close();
}
}

问题:
alert(req.status); 输出为404,
求指教。

------解决方案--------------------
404页面不存在,你看看最后连接成的URL地址对不对