Ver Mensaje Individual
  #1 (permalink)  
Antiguo 13/11/2010, 05:26
Avatar de LordJhony
LordJhony
 
Fecha de Ingreso: septiembre-2010
Mensajes: 472
Antigüedad: 13 años, 8 meses
Puntos: 24
Error Con Combos Dependientes En Jsp

Hola....
Tengo el siguiente codigo Jsp.
Código HTML:
Ver original
  1. <script type="text/javascript">
  2. var peticion = false;
  3. var  testPasado = false;
  4. try
  5. {
  6.         peticion = new XMLHttpRequest();
  7.     }
  8.     catch (trymicrosoft)
  9.     {
  10.     try
  11.     {
  12.         peticion = new ActiveXObject("Msxml2.XMLHTTP");
  13.     }
  14.     catch (othermicrosoft)
  15.     {
  16.         try
  17.         {
  18.             peticion = new ActiveXObject("Microsoft.XMLHTTP");
  19.         }
  20.         catch (failed)
  21.         {
  22.         peticion = false;
  23.         }
  24.     }
  25. }
  26.  
  27. if (!peticion)
  28. alert("ERROR AL INICIALIZAR!");
  29.  
  30. function cargarCombo (url, comboAnterior, element_id)
  31. {
  32.     //Obtenemos el contenido del div
  33.     //donde se cargaran los resultados
  34.     var element =  document.getElementById(element_id);
  35.     //Obtenemos el valor seleccionado del combo anterior
  36.     var valordepende = document.getElementById(comboAnterior)
  37.     var x = valordepende.value
  38.     //construimos la url definitiva
  39.     //pasando como parametro el valor seleccionado
  40.     var fragment_url = url+'?Id_Facultad='+ x ;
  41.     //abrimos la url
  42.     peticion.open("GET", fragment_url);
  43.     peticion.onreadystatechange = function()
  44.     {
  45.         if (peticion.readyState == 4)
  46.         {
  47.             //escribimos la respuesta
  48.             element.innerHTML = peticion.responseText;
  49.         }
  50.     }
  51.    peticion.send(null);
  52. }
  53. <select name="facultad" onchange="javascript:cargarCombo('prueba.jsp', 'facultad', 'div_prueba')" id="facultad">
  54.  
  55.                     <option></option>
  56.                  <%
  57.                  if (!admin.isClosed())
  58.                  {
  59.                       ingreso = admin.createStatement();
  60.                       valida = ingreso.executeQuery("select Id_Facultad, Nombre from simulador_ecaes.facultad" );
  61.                      
  62.                       System.out.println(valida);
  63.                       while (valida.next())
  64.                       {
  65.                          String idfac=valida.getString("Id_Facultad");
  66.                          String nomfac=valida.getString("Nombre");
  67.                          out.println("<option value='"+idfac+"'>"+idfac+","+nomfac+"</option>");
  68.                        }
  69.                        admin.close();
  70.                    }
  71.                    else
  72.                      out.println("fallo");
  73.                   %>
  74.                     </select>
  75. <div name="div_prueba"></div>
Este codigo es para generar dos selects que hacen consulta a la base de datos el segundo dependiendo del primero hace una llamada a prueba.jsp
Código HTML:
Ver original
  1. <%
  2. String idfac =  request.getParameter("Id_Facultad").toString();
  3. %>
  4.  
  5.  
  6. <select name="programa"  id="programa" class="select">
  7. <%
  8.   Connection admin=null;
  9.                  Statement ingreso=null;
  10.                  ResultSet valida=null;
  11.                  String conexion="jdbc:mysql://localhost/simulador_ecaes";
  12.    try
  13.    {
  14.        String q =("select * from simulador_ecaes.programa where Id_Facultad = '" + idfac+ "'");
  15.        valida = ingreso.executeQuery(q);
  16.        while (valida.next())
  17.                       {
  18.                          String idpro=valida.getString("Id_Programa");
  19.                          String nompro=valida.getString("Nombre");
  20.                          out.println("<option value='"+idpro+"'>"+idpro+","+nompro+"</option>");
  21.                        }
  22.     }
  23.     catch (Exception e)
  24.     {
  25.         e.printStackTrace();
  26.     }
  27.     valida.close();
  28.     ingreso.close();
  29. %>
El problema es que cuando escogo el valor del primer select me sale el siguiente error:
Cita:
Programa:
HTTP Status 500 -
________________________________________
type Exception report
message
descriptionThe server encountered an internal error () that prevented it from fulfilling this request.
exception
org.apache.jasper.JasperException: java.lang.NullPointerException
root cause
java.lang.NullPointerException
note The full stack traces of the exception and its root causes are available in the GlassFish/v3 logs.
________________________________________
GlassFish/v3
Creo que el problema esta en esta linea que pienso no me esta enviando el valor estraido de la base de datos.
Código HTML:
Ver original
  1. var fragment_url = url+'?Id_Facultad='+ x ;
Pero todo el codigo esta bien formulado creo....
Me pudieran decir por que motivo se me presenta el error y como podria solucionarlo... De antemano muchas gracias