Duvida com JSTL e mvc

5 respostas
TASF
boa tarde gostaria de saber como exibir os dados de um arrayList na minha view, pois tenho o seguinte sevelet:
package br.com.gc.controle;

import java.awt.List;

/**
 * Servlet implementation class ConsultaUsuario
 */
public class ConsultaUsuarioServlet extends HttpServlet {
	private static final long serialVersionUID = 1L;
       
    /**
     * @see HttpServlet#HttpServlet()
     */
    public ConsultaUsuarioServlet() {
        super();
        // TODO Auto-generated constructor stub
    }

    protected void service( HttpServletRequest request,
    		HttpServletResponse response) throws ServletException,
    		IOException {
    	UsuarioBean bean= new UsuarioBean();
    	bean.setIdUser(Integer.parseInt(request.getParameter("codigo")));
    	bean.setNomeUsuario(request.getParameter("nome"));
    	
    	
    	try {
    		UsuarioDAo dao = new UsuarioDAo();
    		//dao.ListarUsuario(bean);
    	
    		ArrayList<UsuarioBean> listaub = (ArrayList<UsuarioBean>) dao.getLista(bean);
    		request.setAttribute("listar", listaub);
        RequestDispatcher rd = request.getRequestDispatcher("/ConsultaUsuario.jsp");
             rd.forward(request,response);
    		for (int i = 0; i < listaub.size(); i++ ) {
    			UsuarioBean ub = listaub.get(i);
    		System.out.println("nome"+ub.getNomeUsuario());	
    		System.out.println("id"+ub.getIdUser());
    		
    		}
    		/*   		for (UsuarioBean lb : listaub) {
    			System.out.println("Nome: " + lb.getNomeUsuario());
    			
    			}
 */   //	dao.ListarUsuario( bean); 
		} catch (SQLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
    	
    	/* RequestDispatcher rd = request.getRequestDispatcher("/lista_usuarios.jsp");
         rd.forward(request,response);*/
    }
    
    
}
que chama o meu modelo
public java.util.List<UsuarioBean> getLista(UsuarioBean bean)throws SQLException{
		
		String sql=("SELECT * from tb001_usuario ");
		PreparedStatement stmt = this.con.prepareStatement(sql);
	//	stmt.setInt(1,bean.getIdUser()); 
		//stmt.setString(2, "%"+ub.getNomeUsuario()+"%");
       ResultSet rs = stmt.executeQuery();
		
		/*
		PreparedStatement stmt = this.con.prepareStatement("select * from tb001_usuario");
		ResultSet rs = stmt.executeQuery();
		*/
		ArrayList<UsuarioBean> list = new ArrayList<UsuarioBean>();
		while(rs.next()){
			
			UsuarioBean usuarioBean = new UsuarioBean();
			usuarioBean.setIdUser(rs.getInt("tb001_id"));
			usuarioBean.setNomeUsuario(rs.getString("tb001_nome"));
			
			list.add(usuarioBean);
		}
		rs.close();
		stmt.close();
		return list;
	
		
	}
e a minha view que deveria exibir os dados da lista porem so exibe o endereço de memoria se nao me engano
br.com.gc.bean.UsuarioBean@36fe970f br.com.gc.bean.UsuarioBean@46f75fe br.com.gc.bean.UsuarioBean@31ab78f8 br.com.gc.bean.UsuarioBean@7092fb41 br.com.gc.bean.UsuarioBean@41ada224 br.com.gc.bean.UsuarioBean@6e700b2b br.com.gc.bean.UsuarioBean@7ded6cb1 br.com.gc.bean.UsuarioBean@6e7b190d br.com.gc.bean.UsuarioBean@53a9dd25
interessante é que na iteração na servlet exibe os nomes no console mas na view nao.

como posso estar listando esses dados na minha view??? desde ja grato a todos

5 Respostas

S

tenta escrever um toString na classe que você exibir e mande exibir um objeto dela na view.
ou você exibir com get também. instanciando a classe e mandando exibir metodo get dela,já que ela está populada com o select.
ela tá exibindo no ConsultaUsuario.jsp ?

TASF

isso ela deve exibir no consulta jsp, e entao para usar o toString precisaria de scriplets e nao gostaria de usar isso, estou fazendo assim

<c:forEach var="listar" items="${listar}" >
${listar }

porem so exibe
isso br.com.gc.bean.UsuarioBean@362f58d7 br.com.gc.bean.UsuarioBean@5e71a70b br.com.gc.bean.UsuarioBean@778df39d br.com.gc.bean.UsuarioBean@87505bd br.com.gc.bean.UsuarioBean@3acbbfa1 br.com.gc.bean.UsuarioBean@1692012f br.com.gc.bean.UsuarioBean@4b8bc03c br.com.gc.bean.UsuarioBean@43f9c9e3 br.com.gc.bean.UsuarioBean@443578f2

alguem sabe como exibir os dados usando JSTL???

S

TASF:
isso ela deve exibir no consulta jsp, e entao para usar o toString precisaria de scriplets e nao gostaria de usar isso, estou fazendo assim

<c:forEach var="listar" items="${listar}" >
${listar }

porem so exibe
isso br.com.gc.bean.UsuarioBean@362f58d7 br.com.gc.bean.UsuarioBean@5e71a70b br.com.gc.bean.UsuarioBean@778df39d br.com.gc.bean.UsuarioBean@87505bd br.com.gc.bean.UsuarioBean@3acbbfa1 br.com.gc.bean.UsuarioBean@1692012f br.com.gc.bean.UsuarioBean@4b8bc03c br.com.gc.bean.UsuarioBean@43f9c9e3 br.com.gc.bean.UsuarioBean@443578f2

alguem sabe como exibir os dados usando JSTL???

Brother o toString é na classe e não no jsp,mais já sei qual é o problema.

<c:forEach var="listar" items="${listar}" >
${listar }

Não exiba só a listar,exiba listar e o atributo da classe,por exemplo
quero listar a classe Usuario

<c:forEach var="usuario" items="${usuarios}" >
${usuario.nome }
${usuario.sobrenome}
${usuario.email}

entendeu?

TASF

Obrigado brother faltava eu definir os atributos da lista mesmo, vlw msmo

S

disponha!

Criado 25 de agosto de 2013
Ultima resposta 25 de ago. de 2013
Respostas 5
Participantes 2