Tengo un jsp, en el cual incluye un servlet dandole un parametro. Y he notado que al ejecutar, el servlet se carga sin problemas, pero se estanca y luego del servlet el codigo html no aparece.
Aparte he notado que el tomcat me bota errores.
Mi duda es si estoy usando bien el servlet, o cuando cargo una pagina, tendria k ejecutar el servlet e incluir el jsp, o cargar el jsp e incluir el servlet? o es indiferente y el error se debe a problemas con el Tomcat?
NETBEANS 6.8 + Apache Tomcat 6.0.2 + mysql
jsp
Código:
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>JSP Page</title>
</head>
<body>
<h1>Zona</h1>
<table width="644" border="1">
<tr class="cabecera_tabla" align="center">
<td width="100">ID</td>
<td width="1000">NOMBRE</td>
<td width="58">MODIFICAR</td>
<td width="58">ELIMINAR</td>
</tr>
<jsp:include page="/ZonaServlet?Tipo=1" flush="true" />
</table>
</body>
</html>
ZonaServlet
Cita:
package proyectozona.servlet;
import proyectozona.bean.ZonaBean;
import proyectozona.login.ZonaLogin;
import java.io.IOException;
import java.io.PrintWriter;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.util.Iterator;
import java.util.List;
import java.util.Vector;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.servlet.RequestDispatcher;
import javax.swing.JOptionPane;
/**
*
* @author Administrador
*/
@WebServlet(name="ZonaServlet", urlPatterns={"/ZonaServlet"})
public class ZonaServlet extends HttpServlet {
/**
* Processes requests for both HTTP <code>GET</code> and <code>POST</code> methods.
* @param request servlet request
* @param response servlet response
* @throws ServletException if a servlet-specific error occurs
* @throws IOException if an I/O error occurs
*/
protected void processRequest(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
response.setContentType("text/html;charset=UTF-8");
PrintWriter out = response.getWriter();
int op;
op= Integer.parseInt(request.getParameter("Tipo"));
switch (op){
case 1:
try {
//ClienteBean oClienteBean = new ClienteBean();
ZonaLogin oZonaLogin = new ZonaLogin();
List ListarZona = new Vector();
ListarZona=oZonaLogin.obtenerListaZona();
int N=0;//Numero de Clientes
for( Iterator it = ListarZona.iterator(); it.hasNext(); ) {
ZonaBean oZonaBean = (ZonaBean)it.next();
N=N+1;
out.println(" <tr class='texto1'>");
out.println("<td>"+oZonaBean.getId_zona()+"</td>");
out.println("<td>"+oZonaBean.getDescripcion()+"</td>");
out.println("<td><a href='ZonaServlet?Tipo=4&idz="+oZonaBean.getId_zon a()+"'>Modificar</a></td>");
out.println("<td><a href='ZonaServlet?Tipo=5&idz="+oZonaBean.getId_zon a()+"'>Eliminar</a></td>");
out.println("</tr>");
// System.out.println(oClienteBean.getdni_cliente() + " : " + oClienteBean.getnombre_cliente());
}
} catch (Exception ex) {
Logger.getLogger(ZonaServlet.class.getName()).log( Level.SEVERE, null, ex);
}
} finally {
out.close();
}
}
}
break;
jsp ejecutado en apache tomcat
Código:
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>JSP Page</title>
</head>
<body>
<h1>Zona</h1>
<table width="644" border="1">
<tr class="cabecera_tabla" align="center">
<td width="100">ID</td>
<td width="1000">NOMBRE</td>
<td width="58">MODIFICAR</td>
<td width="58">ELIMINAR</td>
</tr>
<tr class='texto1'>
<td>1</td>
<td>a1</td>
<td><a href='ZonaServlet?Tipo=4&idz=1'>Modificar</a></td>
<td><a href='ZonaServlet?Tipo=5&idz=1'>Eliminar</a></td>
</tr>
<tr class='texto1'>
<td>0</td>
<td>1</td>
<td><a href='ZonaServlet?Tipo=4&idz=0'>Modificar</a></td>
<td><a href='ZonaServlet?Tipo=5&idz=0'>Eliminar</a></td>
</tr>
Log de error de TOMCAT
Código:
12/06/2010 01:40:38 PM org.apache.catalina.core.StandardWrapperValve invoke
GRAVE: Servlet.service() para servlet jsp lanzó excepción
java.io.IOException: Stream closed
at org.apache.jasper.runtime.JspWriterImpl.ensureOpen(JspWriterImpl.java:204)
at org.apache.jasper.runtime.JspWriterImpl.flushBuffer(JspWriterImpl.java:115)
at org.apache.jasper.runtime.PageContextImpl.release(PageContextImpl.java:188)
at org.apache.jasper.runtime.JspFactoryImpl.internalReleasePageContext(JspFactoryImpl.java:118)
at org.apache.jasper.runtime.JspFactoryImpl.releasePageContext(JspFactoryImpl.java:77)
at org.apache.jsp.listar_005fmesaatencion_jsp._jspService(listar_005fmesaatencion_jsp.java:120)
at org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
at org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:374)
at org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:342)
at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:267)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
at org.netbeans.modules.web.monitor.server.MonitorFilter.doFilter(MonitorFilter.java:390)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:233)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:191)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:128)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:293)
at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:849)
at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:583)
at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:454)
at java.lang.Thread.run(Thread.java:619)