Ver Mensaje Individual
  #1 (permalink)  
Antiguo 29/05/2012, 08:05
losaltlv
 
Fecha de Ingreso: abril-2012
Ubicación: surquillo
Mensajes: 44
Antigüedad: 12 años, 7 meses
Puntos: 0
error con arraylist

hola comunidad tengo un error al pasar una lista de un server a un pag jsp

/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package servelt;

import conec.conexion;
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.sql.*;
import java.util.ArrayList;
import java.util.List;

@WebServlet(name = "Reportes", urlPatterns = {"/Reportes"})
public class Reportes extends HttpServlet {

protected void processRequest(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
response.setContentType("text/html;charset=UTF-8");
PrintWriter out = response.getWriter();

if(request.getParameter("btn")!=null){
cliente_natural(request, response);

}
}
protected void cliente_natural(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
response.setContentType("text/html;charset=UTF-8");
conexion c=new conexion();
PrintWriter out = response.getWriter();


try{
String cod=request.getParameter("txtbus");
ResultSet res2=null;
ArrayList lista=new ArrayList();

Statement mo=c.getConnection().createStatement();
String sql="Select * from producto";
res2=mo.executeQuery(sql);
while(res2.next()){

String codigo=res2.getString(1);
String des=res2.getString(2);
String ma=res2.getString(3);
String ru=res2.getString(4);
String can=res2.getString(5);
String pre=res2.getString(6);
String fec=res2.getString(7);
String fev=res2.getString(8);


lista.add(codigo);
lista.add(des);
lista.add(ma);
lista.add(ru);
lista.add(can);
lista.add(pre);
lista.add(fec);
lista.add(fev);

}
request.setAttribute("lista",lista);
}catch(SQLException ex){

}

}
// <editor-fold defaultstate="collapsed" desc="HttpServlet methods. Click on the + sign on the left to edit the code.">
/**
* Handles the HTTP <code>GET</code> method.
* @param request servlet request
* @param response servlet response
* @throws ServletException if a servlet-specific error occurs
* @throws IOException if an I/O error occurs
*/
@Override
protected void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
processRequest(request, response);
}

/**
* Handles the HTTP <code>POST</code> method.
* @param request servlet request
* @param response servlet response
* @throws ServletException if a servlet-specific error occurs
* @throws IOException if an I/O error occurs
*/
@Override
protected void doPost(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
processRequest(request, response);
}

/**
* Returns a short description of the servlet.
* @return a String containing servlet description
*/
@Override
public String getServletInfo() {
return "Short description";
}// </editor-fold>
}

pagina jsp

<%--
Document : listar
Created on : 24-abr-2012, 15:13:29
Author : clever
--%>

<%@page import="javax.persistence.metamodel.ListAttribute" %>
<%@page import="conec.conexion"%>
<%@ page contentType="text/html; charset=utf-8" language="java" import="java.sql.*" errorPage="" %>
<%@ page import="java.util.ArrayList" %>
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Documento sin título</title>
<style type="text/css">
body,td,th {
color: #00F;
font-weight: bold;
}
body {
background-color: #000;
}
</style>
</head>

<body>
<CENTER><h1>listado de Clientes!</h1></CENTER>
<form name="form1" method="post" action="Reportes">
<table align="center" border="2" >
<tr>
<td>codigo</td>
<td>nombre</td>
<td>edad</td>
<td>direcion</td>
<td>correo</td>
</tr>
<%

ArrayList v = (ArrayList)request.getAttribute("lista");
for(int i=0;i<v.size();i++){
%>
<tr>
<td><%out.println(" "+v.get(i)); %></td>
</tr>
<%
}
%>
</table>
<p>
<label>
<input type="submit" name="btn" id="btn" value="Enviar">
</label>
</p>
</form>
<p>&nbsp;</p>
<p>&nbsp;</p>
<center> <a href="javascript:history.go(-1)">Atrás</a> </center>
</body>
</html>

me sale este error

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 Server Open Source Edition 3.1.1 logs.

espero su ayuda gracias !