Pessoal, bom dia!
Primeiramente quero agradecer a todos do fórum que vem me ajudando com algumas paradas. Eu sou iniciante na programação e as vezes me enrolo com umas besteiras, normal.
Então… dessa vez eu trago outro probleminha ^^.
Estou fazendo um CRUD básico, usando jsp, servlet, banco de dados. Estou fazendo o meu listar em uma página e o meu editar em outra página. O problema que estou tendo com isso é que: qnd eu clico lá no botão pra ele editar (na tabelinha que criei) ele redireciona pra página do editar e repete todos os usu´rios cadastrado no banco. Como eu resolvo isso?
Segue o código do listar(ta bem simples):
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Lista de Alunos</title>
<link href="../css/tabela_style.css" rel="stylesheet">
<script src="../js/chamar_listar.js"></script>
</head>
<%
AlunoControlador alunoControlador = new AlunoControlador();
%>
<body>
<h1>Lista de Alunos</h1>
<table border="1">
<th>ID</th>
<th>NOME</th>
<th>CPF</th>
<th>MATRICULA</th>
<th>EMAIL</th>
<th>CIDADE</th>
<th>ESTADO</th>
<th>AÇÃO</th>
<%
for(Aluno a : alunoControlador.listar()){
%>
<tr>
<td><%=a.getId()%></td>
<td><%=a.getNome()%></td>
<td><%=a.getCpf() %></td>
<td><%=a.getMatricula()%></td>
<td><%=a.getEmail()%></td>
<td><%=a.getCidade()%></td>
<td><%=a.getEstado()%></td>
<td><a href="editar_aluno.jsp?id=<%=a.getId()%>">Editar</a></td>
</tr>
<%
}
%>
</table>
</body>
</html>
E aqui ta o problema eu acho. Esse for each, não sei se assim é a forma mais indicada. É um formulário que trás os valores dos usuários do banco, na minha lógica era pra ele retornar apenas o que eu selecionar lá no listar;/
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Alterar Aluno</title>
<link href="../css/formulario_style.css" rel="stylesheet">
</head>
<body>
<h1>Alterar Cadastro</h1>
<%
AlunoControlador alunoControlador = new AlunoControlador();
%>
<form action="http://localhost:8080/ProjetoCrud/AlunoEditarServlet" method="post">
<fieldset>
<%
for(Aluno a : alunoControlador.listar()){
%>
<fieldset class="grupo">
<div class="campo">
<label for="nome">ID</label> <input type="text" id="nome"
name="nome" style="width: 10em" value="<%=a.getId() %>" />
</div>
<div class="campo">
<label for="nome">Nome</label> <input type="text" id="nome"
name="nome" style="width: 20em" value="<%=a.getNome() %>" />
</div>
<div class="campo">
<label for="cpf">CPF</label> <input type="text" id="cpf" name="cpf"
style="width: 20em" value="<%=a.getCpf()%>" />
</div>
</fieldset>
<div class="campo">
<label for="email">E-mail</label> <input type="email" id="email"
name="email" style="width: 41em" value="<%=a.getEmail()%>" />
</div>
<div class="campo">
<label for="matricula">Matrícula</label> <input type="text"
id="matricula" name="matricula" style="width: 20em" value="" />
</div>
<fieldset class="grupo">
<div class="campo">
<label for="cidade">Cidade</label> <input type="text" id="cidade"
name="cidade" style="width: 20em" value="<%=a.getCidade()%>" />
</div>
<div class="campo">
<label for="estado">Estado</label> <select name="estado"
id="estado">
<option value="">--</option>
<option value="PE">PE</option>
<option value="JP">JP</option>
</select>
</div>
<%} %>
</fieldset>
<button class="botao submit" type="submit" name="submit">Enviar</button>
<input class="botao listar" name="listar" type="button" value="Listar" onClick="listar()">
</fieldset>
</form>
</body>
</html>
Desde já eu sou muito grato.