Ola a todos
Estou tentando executar um servlet porém ele me traz um erro que eu não consigo corrigir.Abaixo o código do servlet:
[code]package aula02;
import java.io.IOException;
import java.io.PrintWriter;
import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import com.sun.org.apache.xerces.internal.impl.xpath.regex.ParseException;
public class CadastrarFuncionario extends javax.servlet.http.HttpServlet implements javax.servlet.Servlet {
public CadastrarFuncionario() {
super();
}
protected void doGet(HttpServletRequest request, final HttpServletResponse response) throws ServletException, IOException {
try {
doService(request, response);
} catch (java.text.ParseException e) {
e.printStackTrace();
}
}
protected void doPost(HttpServletRequest request, final HttpServletResponse response) throws ServletException, IOException {
try {
doService(request, response);
} catch (java.text.ParseException e) {
e.printStackTrace();
}
}
private void doService(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException, java.text.ParseException {
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 = null;
DateFormat df = new SimpleDateFormat("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, (java.sql.Date) nascimento, salario, sexo, temporario);
}catch(Exception e){
throw new ServletException(e);
}
if(funcionario != null){
AcessoBD.cadastrarFuncionario(funcionario);
response.setContentType("text/html");
PrintWriter out = response.getWriter();
out.write("<html><head><title>Funcionários cadastrados</title></head></html>");
out.write("<h1>Funcionários cadastrados</h1><ol>");
List<Funcionario> lista = AcessoBD.listarFuncionarios();
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'>Formulário de Cadastro</a></p></body></html>");
out.close();
}
}
}
agora o erro que ele da:
[/code]ype Exception report
message
description The server encountered an internal error () that prevented it from fulfilling this request.
exception
javax.servlet.ServletException
aula02.CadastrarFuncionario.doService(CadastrarFuncionario.java:55)
aula02.CadastrarFuncionario.doPost(CadastrarFuncionario.java:33)
javax.servlet.http.HttpServlet.service(HttpServlet.java:647)
javax.servlet.http.HttpServlet.service(HttpServlet.java:729)
root cause
java.lang.NullPointerException
sun.misc.FloatingDecimal.readJavaFormatString(FloatingDecimal.java:991)
java.lang.Double.parseDouble(Double.java:482)
aula02.CadastrarFuncionario.doService(CadastrarFuncionario.java:50)
aula02.CadastrarFuncionario.doPost(CadastrarFuncionario.java:33)
javax.servlet.http.HttpServlet.service(HttpServlet.java:647)
javax.servlet.http.HttpServlet.service(HttpServlet.java:729)
note The full stack trace of the root cause is available in the Apache Tomcat/5.5.31 logs.