El caso es, estoy haciendo una especie de biblioteca, donde se pueden reservar y prestar libros, bueno, tengo un JSP llamado libros.jsp (el cual está dentro de WEB-INF), en esta página JSP se muestran los libros en una tabla, luego dentro de cada fila hay un radio button, si señalamos uno y pulsamos sobre un submit que hay, debería volver a recargarse la misma página, pero con otra tabla debajo de la primera donde muestra los ejemplares de ese libro.
Código de libros.jsp
Código:
El fallo da cuando debería aparecer la segunda tabla de los ejemplares después de hacer el submit<%@page import="Clases.MetodosBD"%> <%@page contentType="text/html" pageEncoding="UTF-8"%> <%@taglib uri="http://java.sun.com/jsp/jstl/fmt" prefix="fmt"%> <%@taglib uri="http://java.sun.com/jsp/jstl/core"prefix="c" %> <%@taglib uri="http://java.sun.com/jsp/jstl/sql" prefix="sql"%> <sql:setDataSource var="consulta" driver="com.mysql.jdbc.Driver" url="jdbc:mysql://localhost/biblioteca" user="root" password=""/> <c:if test="${usuario==null || usuario==''}"> <% response.sendRedirect("index.jsp");%> </c:if> <!DOCTYPE html> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"> <c:set var="i" value="${sessionScope['javax.servlet.jsp.jstl.fmt.locale.session']}"></c:set> <fmt:setBundle basename="Bundle.etiquetas"/> <title>JSP Page</title> </head> <body> <h1>Libros de la biblioteca</h1> <c:if test="${usuario!=null && usuario!=''}"> <% if (request.getParameter("id") == null) { %> <sql:query dataSource="${consulta}" var="result"> SELECT * FROM libros; </sql:query> <form action="Redirect"> <table border="1"> <tr> <th><fmt:message key="id"/></th> <th><fmt:message key="titulo"/></th> <th><fmt:message key="autor"/></th> <th><fmt:message key="reservar"/></th> <th><input type="submit" value="Ejemplares"></th> </tr> <c:forEach var="row" items="${result.rows}"> <tr> <td><c:out value="${row.id}"/></td> <td><c:out value="${row.titulo}"/></td> <td><c:out value="${row.autor}"/></td> <td>Reservar</td> <td><input type='radio' name="idlibro" value="${row.id}"/> </td> </tr> </c:forEach> </table> </form> <% } else { %> <sql:query dataSource="${consulta}" var="result"> SELECT * FROM libros; </sql:query> <table border="1"> <tr> <th><fmt:message key="id"/></th> <th><fmt:message key="titulo"/></th> <th><fmt:message key="autor"/></th> <th><fmt:message key="reservar"/></th> <th><input type="submit" value="Ejemplares"></th> </tr> <c:forEach var="row" items="${result.rows}"> <tr> <td><c:out value="${row.id}"/></td> <td><c:out value="${row.titulo}"/></td> <td><c:out value="${row.autor}"/></td> <td>Reservar</td> <td><input type='radio' name="idlibro" value="${row.id}"/> </td> </tr> </c:forEach> </table><br> <h1> Ejemplares de:</h1> <sql:query dataSource="${consulta}" var="result"> SELECT * FROM ejemplares where idLibro=<% request.getParameter("id"); %>; </sql:query> <c:out value=" SELECT * FROM ejemplares where idLibro=<% request.getParameter('id'); %>;"/> <table border="1"> <tr> <th><fmt:message key="idLibro"/></th> <th><fmt:message key="idEjemplar"/></th> <th><fmt:message key="edicion"/></th> <th><fmt:message key="Disponible"/></th> </tr> <tr> <td><c:out value="${row.idLibro}"/></td> <td><c:out value="${row.idEjemplar}"/></td> <td><c:out value="${row.edicion}"/></td> <td>Disponible/No disponible</td> </tr> </table> <% }%> </c:if> <a href="index.jsp">Volver</a> </body> </html>
Dejo el código del Servlet que me redirecciona (redirect.java), solo he puesto el código relevante, lo demas es creado automáticamente por netbeans:
Código:
Un saludo y graciasprotected void processRequest(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { response.setContentType("text/html;charset=UTF-8"); HttpSession session = request.getSession(); synchronized (session) { String hidden = request.getParameter("hid"); String hiddenId = request.getParameter("id"); //String hiddenTi = request.getParameter("ti"); String address=""; if (hidden.equals("pres")) { address = "WEB-INF/resultados/prestamos.jsp"; }else if (hidden.equals("lib")) { address = "WEB-INF/resultados/libros.jsp"; }else if(hidden.equals("cr")){ address = "WEB-INF/resultados/closesession.jsp"; } if (hiddenId!=null) { address = "WEB-INF/resultados/libros.jsp"; request.setAttribute("id", hiddenId); //request.setAttribute("Ti", hiddenTi); } RequestDispatcher dispatcher = request.getRequestDispatcher(address); dispatcher.forward(request, response); } }
EDIT: Olvidé las líneas del error:
Cita:
java.lang.NullPointerException
at Servlet.Redirect.processRequest(Redirect.java:43)
at Servlet.Redirect.doGet(Redirect.java:73)
at javax.servlet.http.HttpServlet.service(HttpServlet .java:687)
at javax.servlet.http.HttpServlet.service(HttpServlet .java:790)
at org.apache.catalina.core.StandardWrapper.service(S tandardWrapper.java:1682)
at org.apache.catalina.core.StandardWrapperValve.invo ke(StandardWrapperValve.java:318)
at org.apache.catalina.core.StandardContextValve.invo ke(StandardContextValve.java:160)
at org.apache.catalina.core.StandardPipeline.doInvoke (StandardPipeline.java:734)
at org.apache.catalina.core.StandardPipeline.invoke(S tandardPipeline.java:673)
at com.sun.enterprise.web.WebPipeline.invoke(WebPipel ine.java:99)
at org.apache.catalina.core.StandardHostValve.invoke( StandardHostValve.java:174)
at org.apache.catalina.connector.CoyoteAdapter.doServ ice(CoyoteAdapter.java:415)
at org.apache.catalina.connector.CoyoteAdapter.servic e(CoyoteAdapter.java:282)
at com.sun.enterprise.v3.services.impl.ContainerMappe r$HttpHandlerCallable.call(ContainerMapper.java:45 9)
at com.sun.enterprise.v3.services.impl.ContainerMappe r.service(ContainerMapper.java:167)
at org.glassfish.grizzly.http.server.HttpHandler.runS ervice(HttpHandler.java:201)
at org.glassfish.grizzly.http.server.HttpHandler.doHa ndle(HttpHandler.java:175)
at org.glassfish.grizzly.http.server.HttpServerFilter .handleRead(HttpServerFilter.java:235)
at org.glassfish.grizzly.filterchain.ExecutorResolver $9.execute(ExecutorResolver.java:119)
at org.glassfish.grizzly.filterchain.DefaultFilterCha in.executeFilter(DefaultFilterChain.java:284)
at org.glassfish.grizzly.filterchain.DefaultFilterCha in.executeChainPart(DefaultFilterChain.java:201)
at org.glassfish.grizzly.filterchain.DefaultFilterCha in.execute(DefaultFilterChain.java:133)
at org.glassfish.grizzly.filterchain.DefaultFilterCha in.process(DefaultFilterChain.java:112)
at org.glassfish.grizzly.ProcessorExecutor.execute(Pr ocessorExecutor.java:77)
at org.glassfish.grizzly.nio.transport.TCPNIOTranspor t.fireIOEvent(TCPNIOTransport.java:561)
at org.glassfish.grizzly.strategies.AbstractIOStrateg y.fireIOEvent(AbstractIOStrategy.java:112)
at org.glassfish.grizzly.strategies.WorkerThreadIOStr ategy.run0(WorkerThreadIOStrategy.java:117)
at org.glassfish.grizzly.strategies.WorkerThreadIOStr ategy.access$100(WorkerThreadIOStrategy.java:56)
at org.glassfish.grizzly.strategies.WorkerThreadIOStr ategy$WorkerThreadRunnable.run(WorkerThreadIOStrat egy.java:137)
at org.glassfish.grizzly.threadpool.AbstractThreadPoo l$Worker.doWork(AbstractThreadPool.java:565)
at org.glassfish.grizzly.threadpool.AbstractThreadPoo l$Worker.run(AbstractThreadPool.java:545)
at java.lang.Thread.run(Thread.java:745)
at Servlet.Redirect.processRequest(Redirect.java:43)
at Servlet.Redirect.doGet(Redirect.java:73)
at javax.servlet.http.HttpServlet.service(HttpServlet .java:687)
at javax.servlet.http.HttpServlet.service(HttpServlet .java:790)
at org.apache.catalina.core.StandardWrapper.service(S tandardWrapper.java:1682)
at org.apache.catalina.core.StandardWrapperValve.invo ke(StandardWrapperValve.java:318)
at org.apache.catalina.core.StandardContextValve.invo ke(StandardContextValve.java:160)
at org.apache.catalina.core.StandardPipeline.doInvoke (StandardPipeline.java:734)
at org.apache.catalina.core.StandardPipeline.invoke(S tandardPipeline.java:673)
at com.sun.enterprise.web.WebPipeline.invoke(WebPipel ine.java:99)
at org.apache.catalina.core.StandardHostValve.invoke( StandardHostValve.java:174)
at org.apache.catalina.connector.CoyoteAdapter.doServ ice(CoyoteAdapter.java:415)
at org.apache.catalina.connector.CoyoteAdapter.servic e(CoyoteAdapter.java:282)
at com.sun.enterprise.v3.services.impl.ContainerMappe r$HttpHandlerCallable.call(ContainerMapper.java:45 9)
at com.sun.enterprise.v3.services.impl.ContainerMappe r.service(ContainerMapper.java:167)
at org.glassfish.grizzly.http.server.HttpHandler.runS ervice(HttpHandler.java:201)
at org.glassfish.grizzly.http.server.HttpHandler.doHa ndle(HttpHandler.java:175)
at org.glassfish.grizzly.http.server.HttpServerFilter .handleRead(HttpServerFilter.java:235)
at org.glassfish.grizzly.filterchain.ExecutorResolver $9.execute(ExecutorResolver.java:119)
at org.glassfish.grizzly.filterchain.DefaultFilterCha in.executeFilter(DefaultFilterChain.java:284)
at org.glassfish.grizzly.filterchain.DefaultFilterCha in.executeChainPart(DefaultFilterChain.java:201)
at org.glassfish.grizzly.filterchain.DefaultFilterCha in.execute(DefaultFilterChain.java:133)
at org.glassfish.grizzly.filterchain.DefaultFilterCha in.process(DefaultFilterChain.java:112)
at org.glassfish.grizzly.ProcessorExecutor.execute(Pr ocessorExecutor.java:77)
at org.glassfish.grizzly.nio.transport.TCPNIOTranspor t.fireIOEvent(TCPNIOTransport.java:561)
at org.glassfish.grizzly.strategies.AbstractIOStrateg y.fireIOEvent(AbstractIOStrategy.java:112)
at org.glassfish.grizzly.strategies.WorkerThreadIOStr ategy.run0(WorkerThreadIOStrategy.java:117)
at org.glassfish.grizzly.strategies.WorkerThreadIOStr ategy.access$100(WorkerThreadIOStrategy.java:56)
at org.glassfish.grizzly.strategies.WorkerThreadIOStr ategy$WorkerThreadRunnable.run(WorkerThreadIOStrat egy.java:137)
at org.glassfish.grizzly.threadpool.AbstractThreadPoo l$Worker.doWork(AbstractThreadPool.java:565)
at org.glassfish.grizzly.threadpool.AbstractThreadPoo l$Worker.run(AbstractThreadPool.java:545)
at java.lang.Thread.run(Thread.java:745)