0

I have some doubts about a problem with my lista-dados.jsp.

    <%@ page language="java" contentType="text/html; charset=ISO-8859-1"
    pageEncoding="ISO-8859-1"%>
<%@ page import="java.util.ArrayList" %>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>


<!DOCTYPE html>
<html lang="pt-BR">
<head>
<meta charset="utf-8" />
<title>Insert title here</title>
</head>
<body>
<jsp:useBean id="dao" class="bean.ListaDados" scope="session"/>
<table>

<c:forEach var="contato" items="${dao.lista}">
<tr>
<td>${contato.nome}</td>
<td>${contato.email}</td>
<td>${contato.endereco}</td>
<td>${contato.dataNascimento.time}</td>
</tr>
</c:forEach>
</table>
</body>
</html>

My Class ListaDados:(WEBContent/WEB-INF/classes/bean)

     package bean;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.List;
import br.com.cad.basica.Contato;
import br.com.cad.dao.ConnectDb;
public class ListaDados extends ConnectDb {
    Connection c = this.getConnection();
    PreparedStatement ps = null;
    ResultSet rs = null;
    public List<Contato> getContatos(String cpf) {
         try {
         List<Contato> contatos = new ArrayList<Contato>();
         ps = c.prepareStatement("select * from dados_cadastro where pf_cpf= ? ");
         ps.setString(1, cpf);
         ResultSet rs = ps.executeQuery();

         if (rs.next()){

         Contato contato = new Contato();
         contato.setEmail(rs.getString("pf_email"));
         contato.setNome( rs.getString("pf_nome") );
         contato.setEmail(rs.getString("pf_email"));
         contato.setEndereco(rs.getString("pf_endereco"));


         Calendar data = Calendar.getInstance();
         data.setTime(rs.getDate("pf_dt_nasc"));
         contato.setDataNascimento(data);


         contatos.add(contato);
         }
         rs.close();
         ps.close();
         return contatos;

         } catch (SQLException e) {
        throw new RuntimeException(e);
     }

   }
}

This is my checa.jsp:

<%@ page language="java" import="java.sql.Connection,java.sql.DriverManager,java.sql.SQLException" contentType="text/html; charset=ISO-8859-1"
    pageEncoding="ISO-8859-1"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>


<!DOCTYPE html>
<html lang="pt-BR">
<head>
<meta charset="utf-8" />
<title>Painel Administrativo</title>
<c:choose>
    <c:when test="${ user eq null }">
        <jsp:forward page="erroLogin.jsp" />
    </c:when>
    <c:otherwise>
        <p><h2>Bem-vindo, ${ user.nome }</p></h2>

</head>
<body>
<form action="lista-dados.jsp" method="POST"> 
<label for="cpf">Busque o CPF</label>
<br>
<input type="text" id="cpf" required name="cpf">
<button type="submit">Consultar</button>
<%
            String msg=(String) request.getAttribute("msg");
            if(msg!=null)
                out.println(msg);
%>
</c:otherwise>

</c:choose>  
</form>
</body>
</html>

When I enter a doc number in my servlet checa.jsp and press a submit button, I get an error:

HTTP Status 500 - /lista-dados.jsp (line: 14, column: 0) The value for the useBean class attribute bean.ListaDados is invalid.
    org.apache.jasper.JasperException: /lista-dados.jsp (line: 14, column: 0) The value for the useBean class attribute bean.ListaDados is invalid.
    org.apache.jasper.compiler.DefaultErrorHandler.jspError(DefaultErrorHandler.java:42)
    org.apache.jasper.compiler.ErrorDispatcher.dispatch(ErrorDispatcher.java:443)
    org.apache.jasper.compiler.ErrorDispatcher.jspError(ErrorDispatcher.java:149)
    org.apache.jasper.compiler.Generator$GenerateVisitor.visit(Generator.java:1237)
    org.apache.jasper.compiler.Node$UseBean.accept(Node.java:1182)
    org.apache.jasper.compiler.Node$Nodes.visit(Node.java:2376)
    org.apache.jasper.compiler.Node$Visitor.visitBody(Node.java:2428)
    org.apache.jasper.compiler.Node$Visitor.visit(Node.java:2434)
    org.apache.jasper.compiler.Node$Root.accept(Node.java:475)
    org.apache.jasper.compiler.Node$Nodes.visit(Node.java:2376)
    org.apache.jasper.compiler.Generator.generate(Generator.java:3503)
    org.apache.jasper.compiler.Compiler.generateJava(Compiler.java:250)
    org.apache.jasper.compiler.Compiler.compile(Compiler.java:373)
    org.apache.jasper.compiler.Compiler.compile(Compiler.java:353)
    org.apache.jasper.compiler.Compiler.compile(Compiler.java:340)
    org.apache.jasper.JspCompilationContext.compile(JspCompilationContext.java:646)
    org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:357)
    org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:390)
    org.apache.jasper.servlet.JspServlet.service(JspServlet.java:334)
    javax.servlet.http.HttpServlet.service(HttpServlet.java:728)

I don't understand this error, what's the problem?


The error continues i think my bean there is error but i dont know whats!!

  package bean;
    import br.com.cad.basica.Contato;
import br.com.cad.dao.ConnectDb;
public class ListaDados extends ConnectDb {
    public List<Contato> getContatos() {
         try {
         List<Contato> contatos = new ArrayList<Contato>();
         PreparedStatement stmt = this.getConnection()
         .prepareStatement("select * from dados_cadastro where pf_cpf= ?");
         ResultSet rs = stmt.executeQuery();

         while (rs.next()) {
contatos.add(contato);
         }
         rs.close();
         stmt.close();
         return contatos;

         } catch (SQLException e) {
        throw new RuntimeException(e);
     }

   }
}

         Contato contato = new Contato();

         contato.setNome(rs.getString("pf_nome"));

There is a jsp:

<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
    pageEncoding="ISO-8859-1"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
        <jsp:useBean id="bean" class="bean.ListaDados" />
        <jsp:setProperty name="bean" property="*"/>
        <table>

        <c:forEach var="contato" items="${bean.contatos}">
        <tr>
        <td>${contato.nome}</td>
        </c:forEach>
    </table>

I think the error is just with my ListaDados class but i dont know is correct?

4

1 回答 1

0

您必须根据以下规则更正您的课程:

以下是将 JavaBean 与其他 Java 类区分开来的独特特征:

  1. 它提供了一个默认的、无参数的构造函数。

  2. 它应该是可序列化的并实现 Serializable 接口。

  3. 它可能具有许多可以读取或写入的属性。

  4. 它可能有许多属性的“getter”和“setter”方法。

    public class ListaDados extends ConnectDb implements java.io.Serializable{ public ListaDados(){ } //Your Code haere }

于 2013-07-19T23:14:52.540 回答