3

i tried everything i saw, but without success, if someone can help with that, ooh man ..

The problem is that: I cant put a arraylist to jsp from servlet with success, eclipse shows me in JSP that:Uncheked cast from Object to ArrayList,

thats my Servlet Code

    filhoArray = dao.consultar_cpf(mae);
    request.setAttribute("filho", filhoArray);
    getServletConfig().getServletContext().getRequestDispatcher("/resultado-consulta.jsp").forward(request,response);

and JSP

Bebe bebe = new Bebe();

ArrayList<Bebe> list = (ArrayList<Bebe>) request.getAttribute("filho"); 

System.out.println(list);
out.print(list);
michelpm1
  • 177
  • 1
  • 1
  • 12
  • Take a look: http://stackoverflow.com/questions/20275623/type-safety-unchecked-cast-from-object-to-arraylistmyvariable – renke Oct 20 '15 at 19:36

1 Answers1

2

This is a warning that you are casting from a non-generic type to a generic type. In your special situation you can't avoid this cast and therefore you can silence the warning by writing:

@SuppressWarnings("unchecked")
ArrayList<Bebe> list = (ArrayList<Bebe>) request.getAttribute("filho"); 
Community
  • 1
  • 1
wero
  • 32,544
  • 3
  • 59
  • 84
  • The only way to go, if your Model is good, then you could add these annotation to suppress these warning. But don't go these way everytime. Create Data Transfer Obejcts (aka DTO) is a good way to manage informations between applications layers, especially Domain Model and Presentation or between Domain Model and Database. Good luck! – BendaThierry.com Oct 20 '15 at 19:47
  • thanks man, i saw now =D, i hate warnings, and i cant let go.. haha, i wrote: for(int i = 0; i < list.size(); i++) { bebe = list.get(i); out.println( bebe.getNome()); out.println( bebe.getDataNascimento()); and them the values come to the screen – michelpm1 Oct 20 '15 at 20:00