SimpleDateFormat

3 respostas
A

Pessoal;

Alguem poderia me ajudar com o código abaixo? Tô usando o SimpleDateFormat para validar uma data mas ele tá me retornando erro: Segue o código:

<%@ page import=“java.util., java.text., user.*” %>

Cadastro de Usuario
<%

String nome = request.getParameter(“nome”);

String email = request.getParameter(“email”);

String dataNascimento = request.getParameter(“dataNascimento”);

String cargo = request.getParameter(“cargo”);

String statusFeriasStr = request.getParameter(“statusFerias”);

SimpleDateFormat dataNascimento = new SimpleDateFormat(“dd/MM/yyyy”);
Date d = dataNascimento.parse(dataNascimento);

if ((nome == null) || (email == null) || (cargo == null) || (dataNascimento.parse())){
%>

<jsp:forward page="/criacaoUserFalhou.jsp"/>

<% } else { %>

//UsuarioNormal usuario = new UsuarioNormal(nome, email, dataNascimento, cargo, statusFerias);
   	
//Controller.adicionarUsuarioNormal(usuario); 

<jsp:forward page="/CadastroTarefa.html"/>

<% } %>

ERRO -----------------------------------------------------------------------------

HTTP Status 500 -


type Exception report

message

description The server encountered an internal error () that prevented it from fulfilling this request.

exception

org.apache.jasper.JasperException: Unable to compile class for JSP

An error occurred at line: 6 in the jsp file: /Cadastro_User.jsp

Generated servlet error:

C:\Arquivos de programas\Apache Software Foundation\Tomcat 5.0\work\Catalina\localhost\inf1371\org\apache\jsp\Cadastro_005fUser_jsp.java:58: dataNascimento is already defined in _jspService(javax.servlet.http.HttpServletRequest,javax.servlet.http.HttpServletResponse)

SimpleDateFormat dataNascimento = new SimpleDateFormat(dd/MM/yyyy);

^
An error occurred at line: 6 in the jsp file: /Cadastro_User.jsp

Generated servlet error:

C:\Arquivos de programas\Apache Software Foundation\Tomcat 5.0\work\Catalina\localhost\inf1371\org\apache\jsp\Cadastro_005fUser_jsp.java:59: cannot resolve symbol

symbol  : method parse (java.lang.String)

location: class java.lang.String

Date d = dataNascimento.parse(dataNascimento);

^
An error occurred at line: 6 in the jsp file: /Cadastro_User.jsp

Generated servlet error:

C:\Arquivos de programas\Apache Software Foundation\Tomcat 5.0\work\Catalina\localhost\inf1371\org\apache\jsp\Cadastro_005fUser_jsp.java:63: cannot resolve symbol

symbol  : method parse ()

location: class java.lang.String

if ((nome == null) || (email == null) || (cargo == null) || (dataNascimento.parse())){

^

3 errors

3 Respostas

furutani

O problema ocorre pq vc esta declarando duas vezes a variavel dataNascimento.

R

anferreira:
Pessoal;

Alguem poderia me ajudar com o código abaixo? Tô usando o SimpleDateFormat para validar uma data mas ele tá me retornando erro: Segue o código:

<%@ page import=“java.util., java.text., user.*” %>

Cadastro de Usuario
<%

String nome = request.getParameter(“nome”);

String email = request.getParameter(“email”);

String dataNascimento = request.getParameter(“dataNascimento”);

String cargo = request.getParameter(“cargo”);

String statusFeriasStr = request.getParameter(“statusFerias”);

SimpleDateFormat dataNascimento = new SimpleDateFormat(“dd/MM/yyyy”);
Date d = dataNascimento.parse(dataNascimento);

if ((nome == null) || (email == null) || (cargo == null) || (dataNascimento.parse())){
%>

<jsp:forward page="/criacaoUserFalhou.jsp"/>

<% } else { %>

//UsuarioNormal usuario = new UsuarioNormal(nome, email, dataNascimento, cargo, statusFerias);
   	
//Controller.adicionarUsuarioNormal(usuario); 

<jsp:forward page="/CadastroTarefa.html"/>

<% } %>

ERRO -----------------------------------------------------------------------------

HTTP Status 500 -


type Exception report

message

description The server encountered an internal error () that prevented it from fulfilling this request.

exception

org.apache.jasper.JasperException: Unable to compile class for JSP

An error occurred at line: 6 in the jsp file: /Cadastro_User.jsp

Generated servlet error:

C:\Arquivos de programas\Apache Software Foundation\Tomcat 5.0\work\Catalina\localhost\inf1371\org\apache\jsp\Cadastro_005fUser_jsp.java:58: dataNascimento is already defined in _jspService(javax.servlet.http.HttpServletRequest,javax.servlet.http.HttpServletResponse)

SimpleDateFormat dataNascimento = new SimpleDateFormat(dd/MM/yyyy);

^
An error occurred at line: 6 in the jsp file: /Cadastro_User.jsp

Generated servlet error:

C:\Arquivos de programas\Apache Software Foundation\Tomcat 5.0\work\Catalina\localhost\inf1371\org\apache\jsp\Cadastro_005fUser_jsp.java:59: cannot resolve symbol

symbol  : method parse (java.lang.String)

location: class java.lang.String

Date d = dataNascimento.parse(dataNascimento);

^
An error occurred at line: 6 in the jsp file: /Cadastro_User.jsp

Generated servlet error:

C:\Arquivos de programas\Apache Software Foundation\Tomcat 5.0\work\Catalina\localhost\inf1371\org\apache\jsp\Cadastro_005fUser_jsp.java:63: cannot resolve symbol

symbol  : method parse ()

location: class java.lang.String

if ((nome == null) || (email == null) || (cargo == null) || (dataNascimento.parse())){

^

3 errors

Voce já conseguiu resolver o problema do SimpleDateFormat?
Abraço!!!

digaum

O erro ta em declarar duas vezes a variavel dataNascimento, como disse o amigo acima…

Criado 29 de março de 2006
Ultima resposta 5 de nov. de 2007
Respostas 3
Participantes 4