使用ajax抛出406错误, 如何解决?
使用ajax实现一动态弹出窗口, 在本机测试没有任何问题, 部署到服务器后,测试时页面抛出406错误。
在网上查是 MIME无法识别, 我个人认为应该服务器配置问题。
处理ajax请求的大致代码如下:
public void doPost(HttpServletRequest req, HttpServletResponse res) throws java.io.IOException {
List orderIdList = null;
String promotion = req.getParameter("promotion");
String startDate = (req.getParameter("startDate").equals("")) ? null : req.getParameter("startDate");
String endDate = (req.getParameter("endDate").equals("")) ? null : req.getParameter("endDate");
if (promotion != null) {
SimpleReport obj = new SimpleReport();
orderIdList = obj.getOrderIDsbyPromotion(promotion, startDate, endDate);
}
String returnXml = toXML(orderIdList);
res.setContentType("text/xml");
res.getWriter().write(returnXml);
}
public void doGet(HttpServletRequest req, HttpServletResponse res) throws java.io.IOException {
doPost(req,res);
}
public String toXML(List orderIdList) {
StringBuffer xml = new StringBuffer();
xml.append("<?xml version=\"1.0\"?>");
xml.append("<OrderList>");
if (orderIdList != null) {
for (int i=0; i<orderIdList.size(); i++) {
String orderId = ( (Integer)orderIdList.get(i) ).toString();
xml.append("<OrderID>" + orderId + "</OrderID>");
}
}
xml.append("</OrderList>");
return xml.toString();
}
有谁知道该如何解决? Thanks a lot.