Foros del Web » Programación para mayores de 30 ;) » Java »

error con arraylist

Estas en el tema de error con arraylist en el foro de Java en Foros del Web. hola comunidad tengo un error al pasar una lista de un server a un pag jsp /* * To change this template, choose Tools | ...
  #1 (permalink)  
Antiguo 29/05/2012, 08:05
 
Fecha de Ingreso: abril-2012
Ubicación: surquillo
Mensajes: 44
Antigüedad: 12 años
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 !
  #2 (permalink)  
Antiguo 30/05/2012, 02:58
Avatar de Fuzzylog  
Fecha de Ingreso: agosto-2008
Ubicación: En internet
Mensajes: 2.511
Antigüedad: 15 años, 8 meses
Puntos: 188
Respuesta: error con arraylist

Basicamente que alguno de los objetos sobre los que estás realizando alguna opción es null, ahora te queda ver cual de ellos es null y por qué.

Normalmente la traza completa de la excepción (El stack trace) te dice que es lo que falla exactamente.

Si no, por la via dura, te toca hacer debug, o si no puedes sacar por consola todas la variables sobre las que estás haciendo algo (usar un método, añadir un atributo...).
__________________
if (fuzzy && smooth) {
fuzzylog = "c00l";
return true;
}
  #3 (permalink)  
Antiguo 31/05/2012, 16:13
 
Fecha de Ingreso: abril-2012
Ubicación: surquillo
Mensajes: 44
Antigüedad: 12 años
Puntos: 0
Respuesta: error con arraylist

lo q trato es solo mostrar un array de un servelt a un jsp pero no me sale
esto lo q qiero hacer en si
-almacenar datos de una base de datos en una arrylist hecha en un servelt
-esa array q tiene lso adtos almacenados mostrarlos en un jsp

Última edición por losaltlv; 31/05/2012 a las 16:26
  #4 (permalink)  
Antiguo 01/06/2012, 01:33
Avatar de Fuzzylog  
Fecha de Ingreso: agosto-2008
Ubicación: En internet
Mensajes: 2.511
Antigüedad: 15 años, 8 meses
Puntos: 188
Respuesta: error con arraylist

Trata de imprimir por consola o meter en log los valores de los objetos de esta parte del código.

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);

Seguramente algo que esperas que no sea null te está viniendo como null y tienes que encontrarlo para poder arreglarlo.
__________________
if (fuzzy && smooth) {
fuzzylog = "c00l";
return true;
}

Etiquetas: arraylist, jsp, string
Atención: Estás leyendo un tema que no tiene actividad desde hace más de 6 MESES, te recomendamos abrir un Nuevo tema en lugar de responder al actual.
Respuesta




La zona horaria es GMT -6. Ahora son las 18:44.