Ver Mensaje Individual
  #2 (permalink)  
Antiguo 04/11/2005, 06:30
zacjack
 
Fecha de Ingreso: noviembre-2005
Mensajes: 12
Antigüedad: 18 años, 6 meses
Puntos: 0
Continuacion del codigo

Esta es la etructura de directorios, espero aqui se entienda mejor
+ /SIAP
---+ /WEB-INF
--------+ /classes
------------+ /mypack
------------------ *.class
--------+ /src
------------+ /mypack
------------------- *.java ****
--------+ /lib
------------ *.jar
--------- web.xml ****
----+ /META-INF
--------- context.xml ****
----+ /others
-----------*.gif, *.jpg, *.etc
---- *.htm
---- *.jsp

y la verdad es que el mensaje anterior era originalmente mas largo, pero por el limite de 1000 caracteres, tuve que pasar esto para este otro mensaje

/libreria/ContextListener.java es:

************************************************** **************************************
package libreria;

import javax.servlet.*;

public final class ContextListener implements ServletContextListener {

public void contextInitialized (ServletContextEvent servletContextEvent) {
ServletContext servletContext = servletContextEvent.getServletContext ();
try {
LibrosBD librosBD = new LibrosBD ();
servletContext.setAttribute ("BaseDatos", librosBD);
}
catch (Exception e) {
servletContext.log ("No se pudo crear el atributo BaseDatos: " + e.getMessage ());
}
}

public void contextDestroyed (ServletContextEvent servletContextEvent) {
ServletContext servletContext = servletContextEvent.getServletContext ();
LibrosBD librosBD= (LibrosBD) servletContext.getAttribute ("BaseDatos");
librosBD.close ();
servletContext.removeAttribute ("BaseDatos");
}

}
************************************************** ***************************************

/libreria/LibrosBD.java es:

************************************************** ***************************************
package libreria;

import java.sql.*;
import java.util.*;
import javax.sql.*;
import javax.naming.*;

public class LibrosBD {
Connection connection;
private boolean connectionFree = true;
private ArrayList libros;

public LibrosBD () throws Exception {
try {
InitialContext initialContext = new InitialContext ();
Context envContext = (Context) initialContext.lookup ("java:comp/env");
DataSource dataSource = (DataSource) envContext.lookup ("jdbc/siapDB");
this.connection = dataSource.getConnection ();
}
catch (Exception e) {
throw new Exception ("No se pudo abrir la base de datos SIAP: " + e.getMessage ());
}
}

protected synchronized Connection getConnection () {
while (this.connectionFree == false) {
try {
wait ();
}
catch (InterruptedException e) {
}
}
this.connectionFree = false;
notify ();
return this.connection;
}

protected synchronized void releaseConnection () {
while (this.connectionFree == true) {
try {
wait ();
}
catch (InterruptedException e) {
}
}
this.connectionFree = true;
notify ();
}

public Libro getLibro (String Cod_equipo) {
try {
this.getConnection ();
PreparedStatement preparedStatement = this.connection.prepareStatement ("SELECT *.*

FROM libros WHERE Cod_equipo = ?");
preparedStatement.setString (1, Cod_equipo);
ResultSet resultSet = preparedStatement.executeQuery ();
if (resultSet.next ()) {
Libro libro = new Libro (resultSet.getString (1), resultSet.getString (2));
preparedStatement.close ();
this.releaseConnection ();
return libro;
}
else {
preparedStatement.close ();
this.releaseConnection ();
return null;
}
}
catch (SQLException e) {
this.releaseConnection ();
return null;
}
}

public Collection getLibros () {
libros = new ArrayList ();
try {
this.getConnection ();
PreparedStatement preparedStatement = this.connection.prepareStatement ("SELECT

Cod_equipo, nombre FROM equipo");
ResultSet resultSet = preparedStatement.executeQuery ();
while (resultSet.next ()) {
Libro libro = new Libro (resultSet.getString (1), resultSet.getString (2));
libros.add (libro);
}
preparedStatement.close ();
}
catch (SQLException e) {
return null;
}
this.releaseConnection ();

return libros;
}

public void close () {
try {
this.connection.close ();
}
catch (SQLException e) {
System.out.println (e.getMessage ());
}
}
}
************************************************** ***************************************

y el error guardado en logs/localhost.yyyy.mm.dd.txt

************************************************** ****************************************
3/11/2005 10:38:53 PM org.apache.catalina.core.StandardWrapperValve invoke
GRAVE: Servlet.service() para servlet jsp lanzó excepción
java.lang.NullPointerException
at org.apache.jsp.equipo_jsp._jspService(org.apache.j sp.equipo_jsp:62)
at org.apache.jasper.runtime.HttpJspBase.service(Http JspBase.java:97)
at javax.servlet.http.HttpServlet.service(HttpServlet .java:802)
at org.apache.jasper.servlet.JspServletWrapper.servic e(JspServletWrapper.java:322)
at org.apache.jasper.servlet.JspServlet.serviceJspFil e(JspServlet.java:291)
at org.apache.jasper.servlet.JspServlet.service(JspSe rvlet.java:241)
at javax.servlet.http.HttpServlet.service(HttpServlet .java:802)
at

org.apache.catalina.core.ApplicationFilterChain.in ternalDoFilter(ApplicationFilterChain.java:252)
at

org.apache.catalina.core.ApplicationFilterChain.do Filter(ApplicationFilterChain.java:173)
at org.apache.catalina.core.StandardWrapperValve.invo ke(StandardWrapperValve.java:213)
at org.apache.catalina.core.StandardContextValve.invo ke(StandardContextValve.java:178)
at org.apache.catalina.core.StandardHostValve.invoke( StandardHostValve.java:126)
at org.apache.catalina.valves.ErrorReportValve.invoke (ErrorReportValve.java:105)
at org.apache.catalina.core.StandardEngineValve.invok e(StandardEngineValve.java:107)
at org.apache.catalina.connector.CoyoteAdapter.servic e(CoyoteAdapter.java:148)
at org.apache.coyote.http11.Http11Processor.process(H ttp11Processor.java:856)
at

org.apache.coyote.http11.Http11Protocol$Http11Conn ectionHandler.processConnection(Http11Protocol.

java:744)
at org.apache.tomcat.util.net.PoolTcpEndpoint.process Socket(PoolTcpEndpoint.java:527)
at

org.apache.tomcat.util.net.LeaderFollowerWorkerThr ead.runIt(LeaderFollowerWorkerThread.java:80)
at org.apache.tomcat.util.threads.ThreadPool$ControlR unnable.run(ThreadPool.java:684)
at java.lang.Thread.run(Thread.java:595)
************************************************** *****************************************


// bastante largo, pero la verdad es que pense que entre mas especifico fuera mas facil

comprenderian el problema y mas rapido podria solucionarlo.

De antemano, agradezco a todo aquel que dedique algo de su tiempo para atender mi inquietud.
Mi correo es: [email protected]
pongo la direccion de correo, porque este mensaje esta en varios foros y asi me es mas facil leer

sus comentarios, de nuevo gracias.

Zacjack_