Java web

Cara eu sou iniciante em java web mais sei fazer um cadastro simples, e eu fiz um que tem os seguintes caracteres, ID,NOME,ENDEREÇO,EMAIL E SENHA, ai beleza ele da certo faz conexão com o banco normal, mais eu fiz um igual e coloquei mais itens ID,NOME,ENDEREÇO,EMAIL,CIDADE,CEP E SENHA ai ele nao da certo alguem pode me explicar porfavor,valeu!!! :cry:

Bom dia amigo,

Seja bem vindo. Vamos lah, voce estah utilizando JDBC puro? Nós precisamos dar uma olhada no seu código ou nas mensagens de erro pare lhe dar um norte. Posta o que jah voce fez, velhinho!

[]'s

poe o seu código no forum, só não esquece disso antes: formatação

flw.

package br.com.modelo;

public class Pessoa {
private long id;
private String nome;
private String endereco;
private String email;
private String cidade;
private String senha;
public String getSenha() {
return senha;
}
public void setSenha(String senha) {
this.senha = senha;
}
public long getId() {
return id;
}
public void setId(long id) {
this.id = id;
}
public String getNome() {
return nome;
}
public void setNome(String nome) {
this.nome = nome;
}
public String getEndereco() {
return endereco;
}
public void setEndereco(String endereco) {
this.endereco = endereco;
}
public String getEmail() {
return email;
}
public void setEmail(String email) {
this.email = email;
}
public String getCidade() {
return cidade;
}
public void setCidade(String cidade) {
this.cidade = cidade;
}

}


package br.com.infra;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;

public class ConnectionFactory {

public Connection getConnection()  {
	try {
		Class.forName("com.mysql.jdbc.Driver");
		return DriverManager.getConnection("jdbc:mysql://localhost/Consultaweb", "root", "people");
	} catch (SQLException e) {
		throw new RuntimeException(e);
	}catch (ClassNotFoundException e) {
		throw new RuntimeException(e);
	}

}

}

package br.com.infra;

import java.sql.SQLException;
import java.util.List;

public interface DAO {

public void adciona(T entidade)throws SQLException;
public void altera(T entidade)throws SQLException;
public void deleta(T entidade)throws SQLException;
public T lista(String pesquisa)throws SQLException;
public List<T> listaTudo()throws SQLException;

}


package br.com.dao;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;

import br.com.infra.ConnectionFactory;
import br.com.infra.ConnectionFactory;
import br.com.infra.DAO;
import br.com.modelo.Pessoa;

public class PessoaDAO implements DAO{
private Connection con;

public PessoaDAO() {
	
	this.con = new ConnectionFactory().getConnection();
	
	}



@Override
public void adciona(Pessoa entidade) throws SQLException {
	String sql ="insert into pessoa (nome,endereco,email,cidade,senha)values(?,?,?,?,?)";
	PreparedStatement stmt = null;
	
	try{
		stmt = (PreparedStatement) con.prepareStatement(sql);
		
		stmt.setString(1, entidade.getNome());
		stmt.setString(2, entidade.getEndereco());
		stmt.setString(3, entidade.getEmail());
		stmt.setString(4, entidade.getCidade());
		stmt.setString(5, entidade.getSenha());
		
		stmt.execute();
		
	}catch(SQLException e) {
	  throw new RuntimeException(e);
	}finally{
		con.close();
		stmt.close();
	}
	
	
}

@Override
public void altera(Pessoa entidade) throws SQLException {
	String sql = "update pessoa set";
	int t = 0;
	int count = 1;
	if(entidade.getNome() != null && !entidade.getNome().equals("")) {
		sql = sql + "nome=?";
		t = 1;
	}
	if(entidade.getEndereco() != null && !entidade.getEndereco().equals("")) {
		if(t == 1) {
			sql = sql + ",";
		}
		sql = sql + "endereco=?";
		t = 1;
		}
	if(entidade.getEmail() != null && !entidade.getEmail().equals("")) {
		if(t == 1){
			sql = sql + ",";
		}
		sql = sql + "email=?";
		t = 1;
		}
	if(entidade.getCidade() != null && !entidade.getCidade().equals("")) {
		if(t == 1) {
			sql = sql + ",";
		}
		sql = sql + "cidade=?";
		}
	if(entidade.getSenha() != null && !entidade.getSenha().equals("")) {
		if(t == 1) {
			sql = sql + ",";
		}
		sql = sql + "senha=?";
	}
	sql = sql + "where id=?";
	
	PreparedStatement stmt = null;
	try{
		stmt = (PreparedStatement)con.prepareStatement(sql);
		if(entidade.getNome() != null && !entidade.getNome().equals("")) {
			stmt.setString(count, entidade.getNome());
			count++;
		}
		if(entidade.getEndereco() != null && !entidade.getEndereco().equals("")) {
			stmt.setString(count, entidade.getEndereco());
			count++;
		}
		if(entidade.getEmail() != null && !entidade.getEmail().equals("")) {
			stmt.setString(count, entidade.getEmail());
			count++;
		}
		if(entidade.getCidade() != null && !entidade.getCidade().equals("")) {
			stmt.setString(count, entidade.getCidade());
			count++;
		}
		if(entidade.getSenha() != null && !entidade.getSenha().equals("")) {
			stmt.setString(count, entidade.getSenha());
			count++;
	}
		stmt.setLong(count, entidade.getId());
		stmt.execute();
	}catch(SQLException e) {
		throw new RuntimeException(e);
	}finally{
		con.close();
		stmt.close();
	}
	
}


@Override
public void deleta(Pessoa entidade) throws SQLException {
	PreparedStatement stmt = null;
	try{
		stmt = (PreparedStatement) con.prepareStatement("delete from pessoa where id=?");
		stmt.setLong(1, entidade.getId());
		stmt.execute();
	}catch(SQLException e) {
		throw new RuntimeException(e);
	}finally{
		con.close();
		stmt.close();
		
	}
	
}

@Override
public Pessoa lista(String pesquisa) throws SQLException {
	Pessoa entidade = new Pessoa();
	String sql = "select * from pessoa where id=?";
	PreparedStatement stmt = null;
	ResultSet rs = null;
	try{
		stmt = (PreparedStatement) con.prepareStatement(sql);
		stmt.setLong(1, new Long(pesquisa));
		rs = stmt.executeQuery();
		
		if(rs.next()) {
			entidade.setId(rs.getLong("id"));
			entidade.setNome(rs.getString("nome"));
			entidade.setEndereco(rs.getString("endereco"));
			entidade.setEmail(rs.getString("email"));
			entidade.setCidade(rs.getString("cidade"));
			entidade.setSenha(rs.getString("senha"));
		}
	}catch(SQLException e){
		throw new RuntimeException(e);
		}finally{
			stmt.close();
			rs.close();
			con.close();	
		}
	return entidade;
	}
	

@Override
public List<Pessoa> listaTudo() throws SQLException {
	List<Pessoa> pessoas = new ArrayList<Pessoa>();
	String sql = "select * from pessoa";
	PreparedStatement stmt = null;
	ResultSet rs = null;
	
	try{
		stmt = (PreparedStatement) con.prepareStatement(sql);
		rs = stmt.executeQuery();
		Pessoa entidade = null;
		while (rs.next()) {
			entidade = new Pessoa();
			entidade.setId(rs.getLong("id"));
			entidade.setNome(rs.getString("nome"));
			entidade.setEndereco(rs.getString("endereco"));
			entidade.setEmail(rs.getString("email"));
			entidade.setCidade(rs.getString("cidade"));
			entidade.setSenha(rs.getString("senha"));
			
			pessoas.add(entidade);
			
		}
	}catch(SQLException e) {
		throw new RuntimeException(e);
	}finally{
		stmt.close();
		rs.close();
		con.close();
	}
	return pessoas;
	 
}

}


package br.com.controle;

import java.io.IOException;
import java.io.PrintWriter;
import java.sql.SQLException;

import javax.servlet.RequestDispatcher;
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 br.com.dao.PessoaDAO;
import br.com.modelo.Pessoa;
@WebServlet("/pessoa")
public class PessoaServlet extends HttpServlet {

protected void service(HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException {

	// busca o writer
	PrintWriter out = response.getWriter();
	
	PessoaDAO dao = new PessoaDAO();

	String action = request.getParameter("action");

	if (action != null && action.equals("gravar")) {
		// buscando os parâmetros no request
		Integer id = 0;

		if (request.getParameter("id") != null && !request.getParameter("id").equals("")) {
			id = Integer.parseInt(request.getParameter("id"));
		}
		String nome = request.getParameter("nome");
		String endereco = request.getParameter("endereco");
		String email = request.getParameter("email");
		String cidade = request.getParameter("cidade");
		String senha = request.getParameter("senha");

		Pessoa pessoa = new Pessoa();
		pessoa.setNome(nome);
		pessoa.setEndereco(endereco);
		pessoa.setEmail(email);
		pessoa.setCidade(cidade);
		pessoa.setSenha(senha);

		try {

			if (id != null && id > 0) {
				pessoa.setId(new Long(id));
				dao.altera(pessoa);
			} else {
				dao.adciona(pessoa);
			}

			RequestDispatcher dispatcher = request.getRequestDispatcher("pessoa.jsp");
			dispatcher.forward(request, response);

		} catch (SQLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}

	} else if (action != null && action.equals("excluir")) {

		Integer id = 0;

		if (request.getParameter("id") != null && !request.getParameter("id").equals("")) {
			id = Integer.parseInt(request.getParameter("id"));
		}
		
		Pessoa pessoa = new Pessoa();

		pessoa.setId(new Long(id));

		try {
			dao.deleta(pessoa);
			RequestDispatcher dispatcher = request.getRequestDispatcher("pessoa.jsp");
			dispatcher.forward(request, response);
		} catch (SQLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}

	}else {
		RequestDispatcher dispatcher = request.getRequestDispatcher("pessoa.jsp");
		dispatcher.forward(request, response);
	}

}

}


<%@ 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”%>
<%@ taglib uri=“http://java.sun.com/jsp/jstl/fmt” prefix=“fmt” %>

Pessoa

Cadastro de pessoa

Id:
Nome:
Endereco:
Email:
Cidade:
Senha:
		<br/>
		<div align="center">
			<button id="gravar_submit" onclick="gravar();" value="Gravar">Gravar</button>

			<button id="excluir_submit" onclick="excluir();" value="Excluir">Excluir</button>
			
		</div>
 </form><br>
<p align="center">Desenvolvido por Thiago Augusto Castelhano Teixeira</p>


  <div align="center">
	<table border="1">
		<tr>
			<th>Id</th>
			<th>Nome</th>
			<th>Endereco</th>
			<th>email</th>
			<th>cidade</th>
		</tr></div>
		<!-- percorre contatos montando as linhas da tabela -->
		<c:forEach var="pessoa" items="${dao.listaTudo()}">
			<tr>
				<td>${pessoa.id}</td>
				<td>${pessoa.nome}</td>
				<td>${pessoa.endereco}</td>
				<td>${pessoa.email}</td>
				<td>${pessoa.cidade}</td>
			</tr>
		</c:forEach>
	</table>
</div>

ai vê se alguem consegue me ajudar valeu :roll: :roll:

desculpa o erro que da é erro

HTTP Status 404 - /Consultaweb/pessoa.jsp

type Status report

message /Consultaweb/pessoa.jsp

description The requested resource (/Consultaweb/pessoa.jsp) is not available.

Apache Tomcat/7.0.23

mais quando eu volto o meu programa os meus contatos estao cadastrado o que acontece que eu nao consegui resolver valeu

[quote=thiserver]package br.com.modelo;

public class Pessoa {
private long id;
private String nome;
private String endereco;
private String email;
private String cidade;
private String senha;
public String getSenha() {
return senha;
}
public void setSenha(String senha) {
this.senha = senha;
}
public long getId() {
return id;
}
public void setId(long id) {
this.id = id;
}
public String getNome() {
return nome;
}
public void setNome(String nome) {
this.nome = nome;
}
public String getEndereco() {
return endereco;
}
public void setEndereco(String endereco) {
this.endereco = endereco;
}
public String getEmail() {
return email;
}
public void setEmail(String email) {
this.email = email;
}
public String getCidade() {
return cidade;
}
public void setCidade(String cidade) {
this.cidade = cidade;
}

}


package br.com.infra;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;

public class ConnectionFactory {

public Connection getConnection()  {
	try {
		Class.forName("com.mysql.jdbc.Driver");
		return DriverManager.getConnection("jdbc:mysql://localhost/Consultaweb", "root", "people");
	} catch (SQLException e) {
		throw new RuntimeException(e);
	}catch (ClassNotFoundException e) {
		throw new RuntimeException(e);
	}

}

}

package br.com.infra;

import java.sql.SQLException;
import java.util.List;

public interface DAO {

public void adciona(T entidade)throws SQLException;
public void altera(T entidade)throws SQLException;
public void deleta(T entidade)throws SQLException;
public T lista(String pesquisa)throws SQLException;
public List<T> listaTudo()throws SQLException;

}


package br.com.dao;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;

import br.com.infra.ConnectionFactory;
import br.com.infra.ConnectionFactory;
import br.com.infra.DAO;
import br.com.modelo.Pessoa;

public class PessoaDAO implements DAO{
private Connection con;

public PessoaDAO() {
	
	this.con = new ConnectionFactory().getConnection();
	
	}



@Override
public void adciona(Pessoa entidade) throws SQLException {
	String sql ="insert into pessoa (nome,endereco,email,cidade,senha)values(?,?,?,?,?)";
	PreparedStatement stmt = null;
	
	try{
		stmt = (PreparedStatement) con.prepareStatement(sql);
		
		stmt.setString(1, entidade.getNome());
		stmt.setString(2, entidade.getEndereco());
		stmt.setString(3, entidade.getEmail());
		stmt.setString(4, entidade.getCidade());
		stmt.setString(5, entidade.getSenha());
		
		stmt.execute();
		
	}catch(SQLException e) {
	  throw new RuntimeException(e);
	}finally{
		con.close();
		stmt.close();
	}
	
	
}

@Override
public void altera(Pessoa entidade) throws SQLException {
	String sql = "update pessoa set";
	int t = 0;
	int count = 1;
	if(entidade.getNome() != null && !entidade.getNome().equals("")) {
		sql = sql + "nome=?";
		t = 1;
	}
	if(entidade.getEndereco() != null && !entidade.getEndereco().equals("")) {
		if(t == 1) {
			sql = sql + ",";
		}
		sql = sql + "endereco=?";
		t = 1;
		}
	if(entidade.getEmail() != null && !entidade.getEmail().equals("")) {
		if(t == 1){
			sql = sql + ",";
		}
		sql = sql + "email=?";
		t = 1;
		}
	if(entidade.getCidade() != null && !entidade.getCidade().equals("")) {
		if(t == 1) {
			sql = sql + ",";
		}
		sql = sql + "cidade=?";
		}
	if(entidade.getSenha() != null && !entidade.getSenha().equals("")) {
		if(t == 1) {
			sql = sql + ",";
		}
		sql = sql + "senha=?";
	}
	sql = sql + "where id=?";
	
	PreparedStatement stmt = null;
	try{
		stmt = (PreparedStatement)con.prepareStatement(sql);
		if(entidade.getNome() != null && !entidade.getNome().equals("")) {
			stmt.setString(count, entidade.getNome());
			count++;
		}
		if(entidade.getEndereco() != null && !entidade.getEndereco().equals("")) {
			stmt.setString(count, entidade.getEndereco());
			count++;
		}
		if(entidade.getEmail() != null && !entidade.getEmail().equals("")) {
			stmt.setString(count, entidade.getEmail());
			count++;
		}
		if(entidade.getCidade() != null && !entidade.getCidade().equals("")) {
			stmt.setString(count, entidade.getCidade());
			count++;
		}
		if(entidade.getSenha() != null && !entidade.getSenha().equals("")) {
			stmt.setString(count, entidade.getSenha());
			count++;
	}
		stmt.setLong(count, entidade.getId());
		stmt.execute();
	}catch(SQLException e) {
		throw new RuntimeException(e);
	}finally{
		con.close();
		stmt.close();
	}
	
}


@Override
public void deleta(Pessoa entidade) throws SQLException {
	PreparedStatement stmt = null;
	try{
		stmt = (PreparedStatement) con.prepareStatement("delete from pessoa where id=?");
		stmt.setLong(1, entidade.getId());
		stmt.execute();
	}catch(SQLException e) {
		throw new RuntimeException(e);
	}finally{
		con.close();
		stmt.close();
		
	}
	
}

@Override
public Pessoa lista(String pesquisa) throws SQLException {
	Pessoa entidade = new Pessoa();
	String sql = "select * from pessoa where id=?";
	PreparedStatement stmt = null;
	ResultSet rs = null;
	try{
		stmt = (PreparedStatement) con.prepareStatement(sql);
		stmt.setLong(1, new Long(pesquisa));
		rs = stmt.executeQuery();
		
		if(rs.next()) {
			entidade.setId(rs.getLong("id"));
			entidade.setNome(rs.getString("nome"));
			entidade.setEndereco(rs.getString("endereco"));
			entidade.setEmail(rs.getString("email"));
			entidade.setCidade(rs.getString("cidade"));
			entidade.setSenha(rs.getString("senha"));
		}
	}catch(SQLException e){
		throw new RuntimeException(e);
		}finally{
			stmt.close();
			rs.close();
			con.close();	
		}
	return entidade;
	}
	

@Override
public List<Pessoa> listaTudo() throws SQLException {
	List<Pessoa> pessoas = new ArrayList<Pessoa>();
	String sql = "select * from pessoa";
	PreparedStatement stmt = null;
	ResultSet rs = null;
	
	try{
		stmt = (PreparedStatement) con.prepareStatement(sql);
		rs = stmt.executeQuery();
		Pessoa entidade = null;
		while (rs.next()) {
			entidade = new Pessoa();
			entidade.setId(rs.getLong("id"));
			entidade.setNome(rs.getString("nome"));
			entidade.setEndereco(rs.getString("endereco"));
			entidade.setEmail(rs.getString("email"));
			entidade.setCidade(rs.getString("cidade"));
			entidade.setSenha(rs.getString("senha"));
			
			pessoas.add(entidade);
			
		}
	}catch(SQLException e) {
		throw new RuntimeException(e);
	}finally{
		stmt.close();
		rs.close();
		con.close();
	}
	return pessoas;
	 
}

}


package br.com.controle;

import java.io.IOException;
import java.io.PrintWriter;
import java.sql.SQLException;

import javax.servlet.RequestDispatcher;
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 br.com.dao.PessoaDAO;
import br.com.modelo.Pessoa;
@WebServlet("/pessoa")
public class PessoaServlet extends HttpServlet {

protected void service(HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException {

	// busca o writer
	PrintWriter out = response.getWriter();
	
	PessoaDAO dao = new PessoaDAO();

	String action = request.getParameter("action");

	if (action != null && action.equals("gravar")) {
		// buscando os parâmetros no request
		Integer id = 0;

		if (request.getParameter("id") != null && !request.getParameter("id").equals("")) {
			id = Integer.parseInt(request.getParameter("id"));
		}
		String nome = request.getParameter("nome");
		String endereco = request.getParameter("endereco");
		String email = request.getParameter("email");
		String cidade = request.getParameter("cidade");
		String senha = request.getParameter("senha");

		Pessoa pessoa = new Pessoa();
		pessoa.setNome(nome);
		pessoa.setEndereco(endereco);
		pessoa.setEmail(email);
		pessoa.setCidade(cidade);
		pessoa.setSenha(senha);

		try {

			if (id != null && id > 0) {
				pessoa.setId(new Long(id));
				dao.altera(pessoa);
			} else {
				dao.adciona(pessoa);
			}

			RequestDispatcher dispatcher = request.getRequestDispatcher("pessoa.jsp");
			dispatcher.forward(request, response);

		} catch (SQLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}

	} else if (action != null && action.equals("excluir")) {

		Integer id = 0;

		if (request.getParameter("id") != null && !request.getParameter("id").equals("")) {
			id = Integer.parseInt(request.getParameter("id"));
		}
		
		Pessoa pessoa = new Pessoa();

		pessoa.setId(new Long(id));

		try {
			dao.deleta(pessoa);
			RequestDispatcher dispatcher = request.getRequestDispatcher("pessoa.jsp");
			dispatcher.forward(request, response);
		} catch (SQLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}

	}else {
		RequestDispatcher dispatcher = request.getRequestDispatcher("pessoa.jsp");
		dispatcher.forward(request, response);
	}

}

}


<%@ 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”%>
<%@ taglib uri=“http://java.sun.com/jsp/jstl/fmt” prefix=“fmt” %>

Pessoa

Cadastro de pessoa

Id:
Nome:
Endereco:
Email:
Cidade:
Senha:
		<br/>
		<div align="center">
			<button id="gravar_submit" onclick="gravar();" value="Gravar">Gravar</button>

			<button id="excluir_submit" onclick="excluir();" value="Excluir">Excluir</button>
			
		</div>
 </form><br>
<p align="center">Desenvolvido por Thiago Augusto Castelhano Teixeira</p>


  <div align="center">
	<table border="1">
		<tr>
			<th>Id</th>
			<th>Nome</th>
			<th>Endereco</th>
			<th>email</th>
			<th>cidade</th>
		</tr></div>
		<!-- percorre contatos montando as linhas da tabela -->
		<c:forEach var="pessoa" items="${dao.listaTudo()}">
			<tr>
				<td>${pessoa.id}</td>
				<td>${pessoa.nome}</td>
				<td>${pessoa.endereco}</td>
				<td>${pessoa.email}</td>
				<td>${pessoa.cidade}</td>
			</tr>
		</c:forEach>
	</table>
</div>

ai vê se alguem consegue me ajudar valeu :roll: :roll: [/quote]

por favor veja o link que passei para você. E tenta seguir as regras do fórum.