Ver Mensaje Individual
  #1 (permalink)  
Antiguo 25/05/2011, 17:42
darkhell86
 
Fecha de Ingreso: mayo-2011
Mensajes: 1
Antigüedad: 12 años, 10 meses
Puntos: 0
un servlet retorna null un xml.

Tengo un evento con ajax que actualiza los campos de un form en un pagina web. Pero al retornar la respuesta del servlet que hago asi:

protected void processRequest(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
response.setContentType("Content-type: text/xml");

PrintWriter out = response.getWriter();
try {

//String nuevo = "<?xml version='1.0' encoding='ISO-8859-1'?><datos><nombres>jose</nombres><identificacion>123</identificacion><apellidos>finlay</apellidos></datos>";
out.println("<?xml version='1.0' encoding='ISO-8859-1'?>");
out.println("<datos>");
out.println("<identificacion>123</identificacion>");
out.println("<nombres>jose</nombres>");
out.println("<apellidos>finlay</apellidos>");
out.println("</datos>");


out.flush();

} finally {
out.close();
}

NO me carga los datos porque me retorna null en el responseXML.

<script language="javascript">
function nuevoAjax(){
var xmlhttp=false;
try {
xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
} catch (e) {
try {
xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
} catch (E) {
xmlhttp = false;
}
}

if (!xmlhttp && typeof XMLHttpRequest!='undefined') {
xmlhttp = new XMLHttpRequest();
}
return xmlhttp;
}

function traerDatos()
{
var cod=document.getElementById("cedula").value;
var idResponsabl=document.getElementById("idResponsabl e");
var nombresResponsabl=document.getElementById("nombres Responsable");
var apellidosResponsabl=document.getElementById("apell idosResponsable");

var ajax=nuevoAjax();
ajax.open("POST", "RetornaPersona", true);
ajax.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
ajax.send("cedula="+cod);

ajax.onreadystatechange=function()
{
if (ajax.readyState==4)
{
if(ajax.status==200) {
var respuesta=ajax.responseXML;
idResponsabl.value=respuesta.getElementsByTagName( "identificacion")[0].childNodes[0].data;
//aqui me sale error. respuesta = null; nombresResponsabl.value=respuesta.getElementsByTag Name("nombres")[0].childNodes[0].data;
apellidosResponsabl.value=respuesta.getElementsByT agName("apellidos")[0].childNodes[0].data;
}

} else {
alert("Estado: " + ajax.status + "\nMotivo: " + ajax.statusText);
}
}
}
</script>

Muchas gracias al q me pueda colaborar.