Pessoal,
Quando eu envio as informações do form para o servlet, aparece esse erro. Já tentei várias coisas, mas não consigo resolver, alguém pode me ajudar?
Erro:
java.lang.IllegalArgumentException: Cannot format given Object as a Date
java.text.DateFormat.format(Unknown Source)
java.text.Format.format(Unknown Source)
servlets.TdpAltera.processRequest(TdpAltera.java:52)
servlets.TdpAltera.doPost(TdpAltera.java:87)
javax.servlet.http.HttpServlet.service(HttpServlet.java:637)
javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
Estou enviando meu código para quem puder me ajudar, dar uma olhada no que poder estar errado.
Edita.jsp
<%
if(session.getValue("login_portal") != null){
String nomeSession = (String) session.getValue("nomeSession");
String tecnologiaSession = (String) session.getValue("tecnologiaSession");
String idAtaTdp = request.getParameter("idAtaTdp");
String retorno = (String) request.getParameter("retorno");
//out.println(request.getParameter("criadorPos"));
%>
<%@ page contentType="text/html; charset=iso-8859-1" session="true" import="util.*" import="java.sql.*" import="java.util.Date" import="java.text.SimpleDateFormat" errorPage="" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" lang="en">
<head>
<meta http-equiv="content-type" content="text/html; charset=iso-8859-1" />
<meta name="description" content="Your description goes here" />
<meta name="keywords" content="your,keywords,goes,here" />
<meta name="author" content="Design: Marcos Scopel" />
<meta http-equiv="Page-Enter" content="blendTrans(Duration=0)" />
<meta http-equiv="Page-Exit" content="blendTrans(Duration=0)" />
<script type="text/javascript" src="../jscalendar-1.0/calendar.js"></script>
<script type="text/javascript" src="../jscalendar-1.0/calendar-setup.js"></script>
<script type="text/javascript" src="../jscalendar-1.0/lang/calendar-br.js"></script>
<link rel="stylesheet" type="text/css" media="screen,projection" href="../jscalendar-1.0/calendar-blue.css" />
<link rel="stylesheet" type="text/css" media="screen,projection" href="../css/style_screen.css" />
<script>
function logoff (){
top.location.href="index.jsp";
}
</script>
<title>Portal das Tecnologias</title>
</head>
<body>
<div class="page-container-1">
<!-- Buffer before header -->
<div class="bufferPOS">
<%
new Conexao();
ResultSet rs = Conexao.stm.executeQuery("SELECT * FROM tdp_ata where (id_tdp = '"+idAtaTdp+"')");
rs.next();
Date dataEdita = rs.getDate("data");
String gpaEdita = rs.getString("gpa");
String tpaEdita = rs.getString("tpa");
String posEdita = rs.getString("pos");
String assuntoEdita = rs.getString("assunto");
String emissorEdita = rs.getString("emissor");
rs.close();
%>
<TABLE class=tableposres cellSpacing=1 width="90%" align=center>
<TBODY>
<TR>
<TH colspan="3">Ata do TDP</TH>
</TR>
</TABLE>
<!-- FORM 1 -->
<form name="ARTIGO" method="post" action="../TdpAltera" onsubmit="return valida(this);">
<table class=tableposres align="center" style="width: 90%;" border="0" cellpadding="0" cellspacing="2">
<tr>
<td class=rowpos><label for="contact_subject" class=gensmall>*Data Cadastro:</label><br>
<input type="text" name="dataEdita" id="cal-field-1" class="post" size="10" value="<%=FormatadorDatas.formatoBrasil_sem_hora(dataEdita)%>" tabindex="1" maxlength="10"/>
<a href="#"><img src="../images/calendar.png" id="cal-button-1" border="0"></a>
<script type="text/javascript">
Calendar.setup({
inputField : "cal-field-1",
button : "cal-button-1",
align : "Br"
});
</script>
</td>
<td class=rowpos><label for="contact_subject" class=gensmall>GPA:</label><br>
<input type="text" name="gpaEdita" id="gpaEdita" class="post" size="10" value="<%=gpaEdita %>" tabindex="3" maxlength="6"/></td>
<td class=rowpos><label for="contact_subject" class=gensmall>TPA:</label><br>
<input type="text" name="tpaEdita" id="tpaEdita" class="post" size="10" value="<%=tpaEdita %>" tabindex="3" maxlength="6"/></td>
<td class=rowpos><label for="contact_subject" class=gensmall>POS:</label><br>
<input type="text" name="posEdita" id="posEdita" class="post" size="10" value="<%=posEdita %>" tabindex="3" maxlength="6"/></td>
<td class=rowpos><label for="contact_subject" class=gensmall>*EMISSOR:</label><br>
<select name="emissorEdita" size="1" class="select">";
<%
ResultSet rs_combo = Conexao.stm1.executeQuery("select * from usuarios order by nome_usuario");
while(rs_combo.next())
{
%>
<option value=<%=rs_combo.getString("nome_usuario")%> <%if(rs_combo.getString("nome_usuario").equals(emissorEdita)) out.print("selected");%>><%=rs_combo.getString("nome_usuario")%></option>
<%
}
%>
</select>
</td>
</tr>
<tr>
<td class=rowpos colspan="5"><label for="contact_message" class=gensmall>*Assunto:</label><br>
<textarea name="assuntoEdita" id="assuntoEdita" cols="95" class=post rows="10" tabindex="6"><%=assuntoEdita %></textarea></td>
</tr>
<TR>
<TD class=rowpos align=middle colSpan=5><INPUT class=btnmain tabIndex=5 type=submit value="Atualizar" name=btnEdtTdp> <INPUT class=btnmain tabIndex=5 type=button onclick="window.history.back(-1)" value="Cancelar" name=btnCancelar> <INPUT class=btnmain tabIndex=5 type=reset value="Limpar" name=btnLimpar>
</TD>
</TR>
</table>
<input type="hidden" name="acao" value="editarTdp">
<input type="hidden" name="retorno" value="<%=retorno%>">
<input type="hidden" name="idAtaTdp" value="<%=idAtaTdp%>">
</form>
</DIV>
<div class="footer">
<p>Copyright © 2009 SA | All Rights Reserved</p>
</div>
</DIV>
</BODY></HTML>
<%
}
else
{
%>
<%@ include file="../logar.jsp" %>
<%
}
%>
Meu servlet:
TddAltera.java
package servlets;
import java.sql.Statement;
import java.io.IOException;
import java.io.PrintWriter;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import util.Conexao;
import util.FormatadorDatas;
public class TdpAltera extends HttpServlet {
protected void processRequest(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException, SQLException{
response.setContentType("text/html;charset=ISO-8859-1");
PrintWriter out = response.getWriter();
//INICIA AS VARIÁVEIS COMO NULAS
String acao = null;
String hoje = null;
String nomeSession = null;
String dataEdita = null;
Date dataBanco = null;
String dataBancoEdita = null;
String tdpEdita = null;
String gpaEdita = null;
String tpaEdita = null;
String posEdita = null;
String assuntoEdita = null;
String emissorEdita = null;
String idAtaTdp = null;
acao = request.getParameter("acao");
if (acao.equals("editarTdp")) {
new Conexao();
//INICIA DATA DE HOJE
hoje = util.FormatadorDatas.data_hora();
//RECEBE VALORES PASSADOS
nomeSession = request.getParameter("nomeSession");
dataEdita = request.getParameter("dataEdita");
if (!dataEdita.equals("")){
try {
dataBanco = new SimpleDateFormat("dd-MM-yyyy").parse(dataEdita);
} catch (ParseException e) {
e.printStackTrace();
}
dataBancoEdita = new SimpleDateFormat("yyyy-MM-dd").format(dataBanco);
}
tdpEdita = request.getParameter("tdpEdita");
gpaEdita = request.getParameter("gpaEdita");
tpaEdita = request.getParameter("tpaEdita");
posEdita = request.getParameter("posEdita");
assuntoEdita = request.getParameter("assuntoEdita");
emissorEdita = request.getParameter("emissorEdita");
idAtaTdp = request.getParameter("idAtaTdp");
}
if (acao.equals("editarTdp")) {
///////////////////////////////////////////////////////EDITA ATA COORD AC/////////////////////////////////////////////////////
Conexao.stm.executeUpdate("UPDATE ata_tdp SET (data='"+dataBancoEdita+"',pos='"+posEdita+"',tpa='"+tpaEdita+"',gpa='"+gpaEdita+"',assunto='"+assuntoEdita+"',emissor='"+emissorEdita+"' where id_ata =");
out.println("<script>alert(\"Atualização realizada com sucesso.\");</script>");
out.println("<script>window.opener.location.reload()</script>");
out.println("<script>self.close()</script>");
}
//FECHA CONEXÃO COM O BANCO DE DADOS
Conexao.con.close();
}
protected void doGet(HttpServletRequest request, HttpServletResponse response)throws ServletException, IOException {
try {
processRequest(request, response);
} catch (SQLException e) {
e.printStackTrace();
}
}
protected void doPost(HttpServletRequest request, HttpServletResponse response)throws ServletException, IOException {
try {
processRequest(request, response);
} catch (SQLException e) {
e.printStackTrace();
}
}
}
Desde já agradeço a ajuda
Marcos