問題如何使用ajax將XML轉換爲HTML下拉列表?我用GET方法發送參數,但生成XML的JSP文件沒有收到它。我發現發送接收參數
var url = "responsexml.jsp";
url = url + "?projectCode=" + prj.options[prj.selectedIndex].value;
xmlhttp.onreadystatechange=stateChanged;
xmlhttp.open("GET", url, true);
xmlhttp.send(null);
然後在responsexml.jsp我做這樣的:
<%
String projectcode = (String) request.getParameter("projectCode");
System.out.println("++++projectCode:=" + projectcode);
Session s = null;
Transaction tx;
try {
s = HibernateUtil.currentSession();
tx = s.beginTransaction();
Query query = s.createQuery("SELECT from Wa wa where wa.ProjectCode='" + projectcode + "'");
response.setContentType("text/xml");
PrintWriter output = response.getWriter();
output.write("<?xml version=\"1.0\" encoding=\"utf-8\"?>");
//response.setHeader("Cache-Control", "no-cache");
if (projectcode != null) {
for (Iterator it = query.iterate(); it.hasNext();) {
if (it.hasNext()) {
Wa object = (Wa) it.next();
//out.print("<item id=\"" + object.getIdWA() + "\" name=\"" + object.getWAName() + "\" />");
output.write("<wa>");
output.write("<item id=\"" + object.getIdWA() + "\" name=\"" + object.getWAName() + "\" />");
output.write("</wa>");
}
}
}
} catch (HibernateException e) {
e.printStackTrace();
}
%>
</body>
</html>
有了這個代碼,我沒有我的XML文件。我得到這個錯誤:
The server did not understand the request, or the request was invalid. Erreur de traitement de la ressource http://www.w3.o ...