Boa tarde pessoal, estou com um problema em um desenvolvimento básico, mas não consigo achar o problema.. Estou seguindo um mini-curso de Desenvolvimento Web, e estarei disponibilizando o projeto (do Eclipse) para quem queira mexer)...
O objetivo desse aplicativo web é bem simples e básico, vou cadastrar um funcionário, e logo depois mostrar todos os funcionários cadastrados (segundo os códigos)
index.html<?xml version="1.0" encoding="ISO-8859-1" ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1" />
<title>Cadastro de funcionários</title>
</head>
<body>
<hl>Cadastro de funcionário</hl>
<form name="frmCadastro" method='post' action='CadastrarFuncionario'>
<p>Nome: <input type='text' name= 'nome' size='30' /></p>
<p>Data de nascimento: <input type='text' name='nascimento' size='15' /> (dd/mm/aaaa)</p>
<p>Salário: R$ <input type='text' name='salario' size='15' /></p>
<p>Sexo: <input type='radio' name='sexo' value='M'/> Masculino <input type='radio' name='sexo' value='F' /> Feminino</p>
<p><input type='checkbox' name='temporario' value='true' /> Funcionário temporário?</p>
<p><input type='submit' value='Cadastrar' />
</form>
</body>
</html>
package aula01;
import java.util.Date;
public class Funcionario {
private String nome;
private Date nascimento;
private Double salario;
private Character sexo;
private Boolean temporario;
public Funcionario() {}
public Funcionario(String nome, Date nascimento, Double salario, Character sexo, Boolean temporario) {
this.nome = nome;
this.nascimento = nascimento;
this.salario = salario;
this.sexo = sexo;
this.temporario = temporario;
}
public String getNome() {
return nome;
}
public void setNome(String nome) {
this.nome = nome;
}
public Date getNascimento() {
return nascimento;
}
public void setNascimento(Date nascimento) {
this.nascimento = nascimento;
}
public Double getSalario() {
return salario;
}
public void setSalario(Double salario) {
this.salario = salario;
}
public Character getSexo() {
return sexo;
}
public void setSexo(Character sexo) {
this.sexo = sexo;
}
public Boolean getTemporario() {
return temporario;
}
public void setTemporario(Boolean temporario) {
this.temporario = temporario;
}
}
package aula01;
import java.util.ArrayList;
import java.util.List;
public class Dados {
private static List<Funcionario> funcionarios = new ArrayList<Funcionario>();
public static void cadastraFuncionario(Funcionario funcionario) {
funcionarios.add(funcionario);
}
public static List<Funcionario> listaFuncionario() {
return funcionarios;
}
}
package aula01;
import java.io.IOException;
import java.io.PrintWriter;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
/**
* Servlet implementation class for Servlet: CadastrarFuncionarioServlet
*
*/
public class CadastrarFuncionarioServlet extends javax.servlet.http.HttpServlet implements javax.servlet.Servlet {
static final long serialVersionUID = 1L;
/* (non-Java-doc)
* @see javax.servlet.http.HttpServlet#HttpServlet()
*/
public CadastrarFuncionarioServlet() {
super();
}
/* (non-Java-doc)
* @see javax.servlet.http.HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
*/
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
doService(request, response);
}
/* (non-Java-doc)
* @see javax.servlet.http.HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
*/
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
doService(request, response);
}
private void doService(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
String nome = request.getParameter('nome');
String sNascimento = request.getParameter('nascimento');
String sSalario = request.getParameter('salario');
String sSexo = request.getParameter('sexo');
String sTemporario = request.getParameter('temporario');
Funcionario funcionario = nell;
DateFormat df = new SimpleDataFormat('dd/MM/yyyy');
try {
Date nascimento = df.parse(sNascimento);
Double salario = Double.parseDouble(sSalario);
Character sexo = sSexo.charAt(0);
Boolean temporario = Boolean.parseBoolean(sTemporario);
funcionario = new Funcionario(nome, nascimento, salario, sexo, temporario);
}
catch (Exception e) {
throw new ServletException(e);
}
if (funcionario != null) {
Dados.cadastraFuncionario(funcionario);
response.setContentType('text/html');
PrintWriter out = reponse.getWriter();
out.write('<html><head><title>Funcionários cadastrados</title></head></body>');
out.write('<hl>Funcionários cadastrados</hl><ol>');
List<Funcionario> lista = Dados.listaFuncionario();
for (Funcionario f : lista) out.write('<li><p>' + f.getNome() + '</p></li>');
out.write('<ol>');
out.write('<p><hr /></p><p><a href='index.html'>Formulario de cadastro</a></p></body></html>');
out.close();
}
}
}
Agradeço a colaboração!