Boa tarde Galera,
Estou tendo aula de java p web, mas não absorvi bem os conceitos … Tive um exemplo na aula de MVC porém o Prof. passou com scanner para a parte “view” e to tentando fazer um outro e usando JSP. … comecei a fazer p poder compreender e está me gerando dúvidas … gostaria que alguém podesse me orientar…
Dem uma olhada.
package imobiliaria;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.Table;
@Entity
@Table(name="tb_cliente", schema="bd_imobiliaria")
public class Cliente {
@Id
@GeneratedValue(strategy = GenerationType.AUTO)
@Column(name="id_cliente")
private int idCliente;
@Column(name="nm_cliente",nullable=false,length=50)
private String nomeCliente = "";
@Column(name="email_cliente",nullable=false,length=50)
private String emailCliente = "";
@Column(name="rua_cliente",nullable=false,length=100)
private String ruaCliente = "";
@Column(name="cidade_cliente",nullable=false,length=45)
private String cidadeCliente = "";
@Column(name="bairro_cliente",nullable=false,length=45)
private String bairroCliente = "";
@Column(name="num_cliente",nullable=false,length=5)
private String numCliente = "";
@Column(name="cep_cliente",nullable=false,length=9)
private String cepCliente = "";
@Column(name="tel_cliente",nullable=false,length=13)
private String telefoneCliente = "";
@Column(name="cnpj_cliente",nullable=false,length=11)
private String cnpjCliente = "";
@Column(name="cpf_cliente",nullable=false,length=11)
private String cpfCliente = "";
public Cliente() {}
public int getIdCliente() {
return idCliente;
}
public void setIdCliente(int idCliente) {
this.idCliente = idCliente;
}
public String getNomeCliente() {
return nomeCliente;
}
public void setNomeCliente(String nomeCliente) {
this.nomeCliente = nomeCliente;
}
public String getEmailCliente() {
return emailCliente;
}
public void setEmailCliente(String emailCliente) {
this.emailCliente = emailCliente;
}
public String getRuaCliente() {
return ruaCliente;
}
public void setRuaCliente(String ruaCliente) {
this.ruaCliente = ruaCliente;
}
public String getCidadeCliente() {
return cidadeCliente;
}
public void setCidadeCliente(String cidadeCliente) {
this.cidadeCliente = cidadeCliente;
}
public String getBairroCliente() {
return bairroCliente;
}
public void setBairroCliente(String bairroCliente) {
this.bairroCliente = bairroCliente;
}
public String getCepCliente() {
return cepCliente;
}
public void setCepCliente(String cepCliente) {
this.cepCliente = cepCliente;
}
public String getNumCliente() {
return numCliente;
}
public void setNumCliente(String numCliente) {
this.numCliente = numCliente;
}
public String getTelefoneCliente() {
return telefoneCliente;
}
public void setTelefoneCliente(String telefoneCliente) {
this.telefoneCliente = telefoneCliente;
}
public String getCnpjCliente() {
return cnpjCliente;
}
public void setCnpjCliente(String cnpjCliente) {
this.cnpjCliente = cnpjCliente;
}
public String getCpfCliente() {
return cpfCliente;
}
public void setCpfCliente(String cpfCliente) {
this.cpfCliente = cpfCliente;
}
}
package imobiliaria.dao;
import imobiliairia.utils.ConexBDImobiliariaFactory;
import imobiliaria.Cliente;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.SQLException;
import java.util.List;
import org.hibernate.HibernateException;
import org.hibernate.Query;
import org.hibernate.Session;
import org.hibernate.Transaction;
public class ClienteDAO {
private Session sessao;
public void cadastrarCliente(Cliente _cliente) throws Exception
{
sessao = ConexBDImobiliariaFactory.abrirSessao();
Transaction tx = null;
try {
tx = sessao.beginTransaction();
sessao.save(_cliente);
tx.commit();
} catch (HibernateException e) {
e.printStackTrace();
tx.rollback();
} finally {
sessao.close();
}
}
public Cliente consultarCodCliente(int IdCliente)throws Exception
{
sessao = ConexBDImobiliariaFactory.abrirSessao();
Transaction tx = null;
tx = sessao.beginTransaction();
Cliente c1 = (Cliente)sessao.createQuery("from Cliente where codigo = " + IdCliente).uniqueResult();
tx.commit();
sessao.close();
return c1;
}
public List<Cliente> recuperarTodosClientes() throws Exception
{
Session sessao = ConexBDImobiliariaFactory.abrirSessao();
Transaction tx = sessao.beginTransaction();
Query consulta = sessao.createQuery("from Cliente as c order by c.nome ASC");
List list = consulta.list();
List <Cliente> c1 = list;
tx.commit();
sessao.close();
return c1;
}
public List<Cliente> consultarNomeCliente(String nm_cliente)throws Exception
{
Session sessao = ConexBDImobiliariaFactory.abrirSessao();
Transaction tx = sessao.beginTransaction();
Query consulta = sessao.createQuery("from Cliente as c where c.nome like '%" + nm_cliente + "%'");
List list = consulta.list();
List <Cliente> c1 = list;
tx.commit();
sessao.close();
return c1;
}
public void consultar(Cliente cliente)throws Exception{
try{
Class.forName("com.mysql.jdbc.Driver").newInstance();
}
catch(Exception e)
{
}
try{
Connection conexao = DriverManager.getConnection
("jdbc:mysql://localhost/bd_imobiliaria","root","root");
PreparedStatement sql = conexao.prepareStatement
("Insert into tb_cliente (nm_cliente,email_cliente,rua_cliente,cidade_cliente,bairro_cliente" +
"cep_cliente,num_cliente,tel_cliente,cnpj_cliente,cpf_cliente)" +
"value(?,?,?,?,?,?,?,?,?)");
sql.setString(1,cliente.getNomeCliente());
sql.setString(2,cliente.getEmailCliente());
sql.setString(3,cliente.getRuaCliente());
sql.setString(4,cliente.getBairroCliente());
sql.setString(5,cliente.getCepCliente());
sql.setString(6,cliente.getNumCliente());
sql.setString(7,cliente.getTelefoneCliente());
sql.setString(8,cliente.getCnpjCliente());
sql.setString(9,cliente.getCpfCliente());
sql.execute();
conexao.close();
}catch(SQLException e)
{
}
}
}
package imobiliaria.dao;
import imobiliaria.Cliente;
public abstract class IntClienteDAO {
public abstract void cadastrarCliente(Cliente _cliente) throws Exception;
public abstract Cliente consultarCodCliente(int cod_cliente)throws Exception;
}
<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
pageEncoding="ISO-8859-1"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Insert title here</title>
</head>
<body>
<table width="441" border="1" align="center">
<tr align="center" valign="middle">
<td width="45"><a >Iniciar</a></td>
<td width="51"><a >Incluir Cliente</a></td>
<td width="79"><a >Consultar</a></td>
<td width="57"><a >Alterar</a></td>
<td width="61"><a >Buscar</a></td>
<td width="52"><a >Excluir</a></td>
</tr>
</table>
</body>
</html>
<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
pageEncoding="ISO-8859-1"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Insert title here</title>
</head>
<body>
<form action="cliente2.jsp" method="post" onsubmit="return confirm('Confirma de Inclusão?');">
<table width="200" border="1">
<tr>
<td>Nome:</td>
<td><input name="nome" type="text"></td>
</tr>
<tr>
<td>E-mail:</td>
<td><input name="e-mail" type="text"></td>
</tr>
<tr>
<td>Rua :</td>
<td><input name="rua" type="text"></td>
</tr>
<tr>
<td>Cidade:</td>
<td><input name="cidade" type="text"></td>
</tr>
<tr>
<td>Bairro:</td>
<td><input name="bairro" type="text"></td>
</tr>
<tr>
<td>CEP:</td>
<td><input name="cep" type="text"></td>
</tr>
<tr>
<td>Número:</td>
<td><input name="numero" type="text"></td>
</tr>
<tr>
<td>CNPJ:</td>
<td><input name="cnpj" type="text"></td>
</tr>
<tr>
<td>CPF:</td>
<td><input name="cpf" type="text"></td>
</tr>
<tr>
<td><input name="" type="submit" value="Gravar"></td>
<td><input name="" type="reset" value="Limpar"></td>
</tr>
</table>
</form>
</body>
</html>
<%@ page import= "imobiliairia.*" %>
<%@ page import= "imobiliairia.utils.*" %>
<%@ page import= "imobiliaria.dao.*" %>
<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
pageEncoding="ISO-8859-1"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<%@page import="imobiliaria.Cliente"%><html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Insert title here</title>
</head>
<body>
<%
try{
ClienteDAO clienteDAO = new ClienteDAO();
Cliente novoCliente = new Cliente();
novoCliente.setNomeCliente("nomeCliente");
novoCliente.setEmailCliente("emailCliente");
novoCliente.setRuaCliente("ruaCliente");
novoCliente.setCidadeCliente("cidadeCliente");
novoCliente.setBairroCliente("bairroCliente");
novoCliente.setCepCliente("cepCliente");
novoCliente.setNumCliente("numCliente");
novoCliente.setTelefoneCliente("telefoneCliente");
novoCliente.setCnpjCliente("cnpjCliente");
novoCliente.setCpfCliente("cpfCliente");
clienteDAO.consultar(novoCliente);
}
catch (Exception e)
{
e.printStackTrace();
}
%>
</body>
</html>
Fica me aparecendo esse erro aki, e naum sei onde está errado p resolver, pq no cod. naum aparece nada de errado.
HTTP Status 500 -
--------------------------------------------------------------------------------
type Exception report
message
description The server encountered an internal error () that prevented it from fulfilling this request.
exception
javax.servlet.ServletException: java.lang.NoSuchMethodError: org.eclipse.jdt.internal.compiler.CompilationResult.getProblems()[Lorg/eclipse/jdt/core/compiler/CategorizedProblem;
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:275)
javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
root cause
java.lang.NoSuchMethodError: org.eclipse.jdt.internal.compiler.CompilationResult.getProblems()[Lorg/eclipse/jdt/core/compiler/CategorizedProblem;
org.apache.jasper.compiler.JDTCompiler$2.acceptResult(JDTCompiler.java:354)
org.eclipse.jdt.internal.compiler.Compiler.handleInternalException(Compiler.java:446)
org.eclipse.jdt.internal.compiler.Compiler.compile(Compiler.java:381)
org.apache.jasper.compiler.JDTCompiler.generateClass(JDTCompiler.java:413)
org.apache.jasper.compiler.Compiler.compile(Compiler.java:317)
org.apache.jasper.compiler.Compiler.compile(Compiler.java:295)
org.apache.jasper.compiler.Compiler.compile(Compiler.java:282)
org.apache.jasper.JspCompilationContext.compile(JspCompilationContext.java:586)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:317)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:342)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:267)
javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
note The full stack trace of the root cause is available in the Apache Tomcat/6.0.18 logs.
--------------------------------------------------------------------------------
Apache Tomcat/6.0.18
Desde já Obg