Pessoal,
saudações!
Estou desenvolvendo um projeto, mas estou com um problema onde a minha Servlet quando chama JSP a JSP acaba ocorrendo o erro:
org.apache.jasper.JasperException: org.apache.jasper.JasperException: PWC6338: Cannot convert “17:23:54” for the attribute hora_noticia of the bean java.sql.Time: PWC6348: Property editor not registered with the PropertyEditorManager
O attributo que esta ocorrendo o erro é um campo java.sql.time definido no meu javabeans.
Basicamente estou utilizando setAttribute e requestDispatcher na servlet para enviar informações para JSP mas não envia nenhuma informação para JSP.
Na JSP destino da chamada via servlet acaba ocorrendo o erro “PWC6338: Cannot convert “17:23:54” for the attribute hora_noticia of the bean java.sql.Time:” quando execuo o comando <jsp:setProperty name=“noticia” property="*" />
Ja tentei tambem session , getServletContext() e respectivamente na JSP getAttribute(), coloquei javabenas/jsp:setProperty, mas não funcionou…
Por favor alguem pode-me ajudar?
segue os codigos:
Servlet:
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package br.com.noticiasWeb.controler;
//import br.com.noticiasWeb.controler.consistencias.Classe_consiste_noticia;
import br.com.noticiasWeb.modelo.dao.NoticiaDAO;
import br.com.noticiasWeb.modelo.javaBeans.Noticia;
import java.io.IOException;
import java.sql.SQLException;
import java.sql.Time;
import java.text.SimpleDateFormat;
import java.sql.Timestamp;
import java.text.DateFormat;
import java.text.ParseException;
import java.util.Date;
import java.util.logging.Level;
import java.util.logging.Logger;
//import javax.faces.context.FacesContext;
//import java.util.*;
import javax.servlet.RequestDispatcher;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
//import javax.servlet.http.HttpSession;
/**
*
* @author Wanderlei
*/
@WebServlet(name = "ServletController", urlPatterns = {"/ServletController"})
public class ServletControler extends HttpServlet {
//private static final long serialVersionUID =
/**
*
* @param request
* @param response
* @throws ServletException
* @throws IOException
*/
@Override
protected void service(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
//super.service(request, response);
String logica = request.getParameter("Logica");
System.out.println("==> logica= " + logica);
if (logica.equals("cadastrar_Noticia")) {
salvar_Noticia(request, response);
} else {
if (logica.equals("ver_Noticia")) {
try {
visualizar_Noticia(request, response);
} catch (ParseException ex) {
Logger.getLogger(ServletControler.class.getName()).log(Level.SEVERE, null, ex);
}
}
}
}
private void visualizar_Noticia(HttpServletRequest request, HttpServletResponse response) throws ParseException, ServletException, IOException {
// Recuperando noticia
NoticiaDAO nDAO = new NoticiaDAO();
System.out.println("1$ id_usuario: " + request.getParameter("id_usuario"));
// System.out.println(" dt noticia: " + request.getParameter("data_noticia_DMA"));
System.out.println("2 dt noticia AMD: " + request.getParameter("data_noticia_AMD"));
System.out.println("3 hora : " + request.getParameter("hora_noticia"));
System.out.println("4 micro segundo: " + request.getParameter("micro_segundo"));
Noticia noticia = new Noticia();
String w_dat_str = request.getParameter("data_noticia_AMD");
SimpleDateFormat format1 = new SimpleDateFormat("yyyy-MM-dd");
java.sql.Date w_dat_time =
new java.sql.Date(format1.parse(request.getParameter("data_noticia_AMD")).getTime());
System.out.println("# hora_noticia" + request.getParameter("hora_noticia"));
SimpleDateFormat sdf = new SimpleDateFormat("HH:mm:ss");
// String w_hms_atual = sdf.format(new java.util.Date());
java.util.Date horax = sdf.parse(request.getParameter("hora_noticia"));
java.sql.Time w1_hora_noticia = new Time(horax.getTime());
/* System.out.println("5 data_noticia: " + w_dat_time);
System.out.println("6 usuario: " + Integer.parseInt(request.getParameter("id_usuario")));
System.out.println("7 micro_segundo: " + Integer.parseInt(request.getParameter("micro_segundo")));
*/
try {
Noticia n = nDAO.consulta_noticia((Integer.parseInt(request.getParameter("id_usuario"))), w_dat_time, w1_hora_noticia, (Integer.parseInt(request.getParameter("micro_segundo"))));
} catch (SQLException ex) {
Logger.getLogger(ServletControler.class.getName()).log(Level.SEVERE, null, ex);
}
System.out.println("#8 visualizar_Noticia");
// redireciona parapagina de consulta materia
// noticia.setHora_noticia_str(request.getParameter("hora_noticia"));
// noticia.setHora_noticia(null);
//HttpSession sessao = request.getSession(true);
// request.setAttribute("noticia.data_noticia_AMD",noticia.getData_noticia_AMD());
// getServletContext().setAttribute("noticia", noticia);
//this.getServletContext().setAttribute("noticia",noticia);
//response.sendRedirect("/noticia.jsp");
//FacesContext.getCurrentInstance().getExternalContext().getSessionMap().put("noticia",noticia);
//javax.servlet.RequestDispatcher rd = getServletContext().getRequestDispatcher("/noticia.jsp");
request.setAttribute("noticia", noticia);
RequestDispatcher rd = request.getRequestDispatcher("/noticia.jsp");
System.out.println("*** RD= " + rd);
rd.forward(request, response);
// getServletConfig().getServletContext().getRequestDispatcher("/noticia.jsp").forward(request, response);
}
private void salvar_Noticia(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
/* TODO output your page here. You may use following sample code. */
NoticiaDAO nDAO = new NoticiaDAO();
Noticia noticia = new Noticia();
System.out.println("#1 servlet inicio ");
try {
System.out.println("#2 servlet inicio ");
if (request.getParameter("id_usuario").length() == 0
|| request.getParameter("data_noticia_DMA").length() == 0
|| request.getParameter("titulo_manchete").length() == 0
|| request.getParameter("materia").trim().equals("")) {
if (request.getParameter("id_usuario").length() == 0) {
noticia.setId_usuario(null);
}
if (request.getParameter("data_noticia_DMA").length() == 0) {
noticia.setData_noticia_AMD(null);
}
if (request.getParameter("titulo_manchete").length() == 0) {
noticia.setTitulo_manchete("");
}
if (request.getParameter("materia").trim().equals("")) {
noticia.setMateria(null);
}
System.out.println("1 reenvia_Formulario_inclusao ");
reenvia_Formulario_inclusao(noticia, request, response);
return;
}
System.out.println("1$ dt noticia: " + request.getParameter("data_noticia_DMA"));
DateFormat wf_dma1 = new SimpleDateFormat("dd/MM/yyyy");
java.sql.Date Data_amd = new java.sql.Date(wf_dma1.parse(request.getParameter("data_noticia_DMA")).getTime());
String Data_YMD_str = new SimpleDateFormat("yyyy-MM-dd").format(Data_amd);
System.out.println("2# data_ymd_str= " + Data_YMD_str + "# data_amd= " + Data_amd);
noticia.setData_noticia_AMD(Data_amd);
noticia.setId_usuario(Integer.parseInt(request.getParameter("id_usuario")));
noticia.setTitulo_manchete(request.getParameter("titulo_manchete"));
noticia.setMateria(request.getParameter("materia"));
System.out.println("3# data_noticia= " + noticia.getData_noticia_AMD());
if (noticia.getData_noticia_AMD() == null
|| noticia.getId_usuario() == null
|| noticia.getId_usuario() == 0
|| noticia.getTitulo_manchete() == null
|| "".equals(noticia.getTitulo_manchete().trim())
|| noticia.getMateria() == null
|| "".equals(noticia.getMateria().trim())) {
System.out.println("22 reenvia_Formulario_inclusao ");
reenvia_Formulario_inclusao(noticia, request, response);
return;
}
noticia.setData_noticia(Data_amd);
nDAO.adiciona_noticia(noticia);
RequestDispatcher chama_listagem = request.getRequestDispatcher("/lista_noticias.jsp");
System.out.println("6 ==> chama listagem: lista_noticias.jsp " + chama_listagem);
System.out.println(" data_noticia= " + request.getParameter("data_noticia_DMA"));
chama_listagem.forward(request, response);
} catch (ParseException | NumberFormatException | ServletException | IOException e) {
System.out.println("33 reenvia_Formulario_inclusao ");
reenvia_Formulario_inclusao(noticia, request, response);
}
}
private void reenvia_Formulario_inclusao(Noticia noticia, HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
/* System.out.println(" $$$ dt str: " + request.getParameter("data_noticia_DMA") + " @ " + noticia.getData_noticia_AMD());
System.out.println(" autor: " + request.getParameter("id_usuario"));
System.out.println(" titulo: " + request.getParameter("titulo_manchete"));
System.out.println(" materia: " + request.getParameter("materia"));
*/
SimpleDateFormat wf_dma = new SimpleDateFormat("dd/MM/yyyy");
DateFormat wf_amd = new SimpleDateFormat("yyyy-MM-dd");
DateFormat wf_dma2 = new SimpleDateFormat("dd/MM/yyyy");
java.sql.Date wdt2_AMD = java.sql.Date.valueOf(request.getParameter("data_noticia_DMA"));
System.out.println("@ dt2 AMD: " + wdt2_AMD);
noticia.setData_noticia_AMD(wdt2_AMD);
String wdt3_str = wf_amd.format(wdt2_AMD);
request.setAttribute("noticia", request.getParameter("noticia"));
request.setAttribute("noticia.data_noticia_DMA", request.getParameter(wdt3_str));
System.out.println("@ data noticia: " + noticia.getData_noticia_AMD() + " @ " + wdt2_AMD + " @ " + wdt3_str);
RequestDispatcher rd = request.getRequestDispatcher("/inclusao_noticia.jsp");
rd.forward(request, response);
}
}
Jsp (onde esta ocorrendo o erro :PWC6338: Cannot convert “17:23:54” for the attribute hora_noticia of the bean )
<%--
Document : noticia
Created on : 02/12/2012, 10:48:20
Author : Wanderlei
--%>
<%@page language="java" contentType="text/html; charset=ISO-8859-1" pageEncoding="ISO-8859-1"%>
<%@taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<%@taglib uri="http://java.sun.com/jsp/jstl/functions" prefix="fn"%>
<%@taglib uri="http://java.sun.com/jsp/jstl/fmt" prefix="fmt"%>
<%@taglib prefix = "x" uri="http://java.sun.com/jsp/jstl/xml"%>
<%-- <!DOCTYPE html> --%>
<c:import url="cabecalho_noticias.jsp"/>
<jsp:useBean id="noticia" class="br.com.noticiasWeb.modelo.javaBeans.Noticia" scope="request">
</jsp:useBean>
<c:out value='${noticia}'/>
<jsp:setProperty name="noticia" property="*" />
--%>
<%--
<%
Object noticia = request.getAttribute("noticia");
%>
--%>
<%--
<% request.getSession().getAttribute("noticia"); %>
<%--
<%
FacesContext.getCurrentInstance().getExternalContext().getSessionMap().get("noticia");
%>
<% noticia.getMember().setNome(request.getParameter("data_noticia_AMD")); %>
<%--
Object noticia = request.getAttribute("noticia");
%>
<%--
<jsp:getProperty name="noticia" property="data_noticia_AMD" />
--%>
<%--
<jsp:setProperty name="noticia" property="materia" value="${materia}" ></jsp:setProperty>
<jsp:setProperty name="noticia" property="id_usuario" value="${id_usuario}" ></jsp:setProperty>
<jsp:setProperty name="noticia" property="titulo_manchete" value="${titulo_manchete}" ></jsp:setProperty>
<jsp:setProperty name="noticia" property="hora_noticia" value="${hora_noticia}" ></jsp:setProperty>
--%>
<%--
<jsp:setProperty name="noticia" property="data_noticia_AMD" value="${data_noticia_AMD}" ></jsp:setProperty>
--%>
<%=getServletContext().getAttribute("noticia")%>
<table cellpadding="4">
<tr>
<td><b>Data:</b></td>
<td><fmt:formatDate value="${noticia.data_noticia_AMD.time}" pattern="dd/MM/yyyy"/></td>
</tr>
<tr>
<td><b>Hora:</b></td>
<td>${noticia.hora_noticia_str}</td>
</tr>
<tr>
<td><b>Autor:</b></td>
<td>${noticia.id_usuario}</td>
</tr>
<tr>
<td><b>Manchete:</b></td>
<td>${noticia.titulo_manchete}</td>
</tr>
<tr>
<td><b>Noticia:</b></td>
<td width="1000px">${noticia.materia}</td>
</tr>
</table>
<%--
<tag> <name>CustomComponent</name>
<tag-class>com.test.components.CustomComponent</tag-class>
<attribute> <name>someAttribute</name>
<description>The custom attribute</description>
<deferred-value> <type>java.lang.String</type> </deferred-value>
</attribute>
</tag>
--%>
<c:import url="rodape_noticias.jsp"/>
JavaBeans:
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package br.com.noticiasWeb.modelo.javaBeans;
import java.sql.Time;
import java.sql.Date;
import java.sql.SQLException;
import java.text.DateFormat;
import java.text.ParseException;
import java.text.SimpleDateFormat;
//import java.util.Date;
import javax.ejb.Stateless;
/**
*
* @author Wanderlei
*/
@Stateless
/**
*
* @author Wanderlei
*/
public class Noticia {
// public Noticia() {}
/* private Integer id_usuario;
private Calendar data_noticia;
private String titulo_manchete;
private String materia;
*/
private String data_noticia_DMA;
public java.util.Date data_noticia_AMD;
public Integer id_usuario;
public String titulo_manchete;
public String materia;
public java.sql.Date data_noticia;
private Integer micro_segundo;
private String hora_noticia_str;
private java.sql.Time hora_noticia;
/* protected Integer id_usuario;
protected Timestamp data_noticia;
protected String titulo_manchete;
protected String materia;
*/
public Integer getId_usuario() {
return id_usuario;
}
public void setId_usuario(Integer id_usuario) {
this.id_usuario = id_usuario;
}
public Date getData_noticia() {
// System.out.println("get data_noticia= " + data_noticia);
return data_noticia;
}
public void setData_noticia(Date data_noticia) {
this.data_noticia = data_noticia;
// System.out.println("set data_noticia= " + this.data_noticia);
}
public String getTitulo_manchete() {
return titulo_manchete;
}
public void setTitulo_manchete(String titulo_manchete) {
this.titulo_manchete = titulo_manchete;
}
public String getMateria() {
return materia;
}
public void setMateria(String materia) {
this.materia = materia;
}
public Integer getMicro_segundo() {
return micro_segundo;
}
public void setMicro_segundo(Integer micro_segundo) {
this.micro_segundo = micro_segundo;
}
public String getHora_noticia_str() throws ParseException {
System.out.println("2 # hora_hoticia= " + hora_noticia);
SimpleDateFormat sdf = new SimpleDateFormat("HH:mm:ss");
String whora_noticia = sdf.format(hora_noticia);
setHora_noticia_str(whora_noticia);
return hora_noticia_str;
}
public void setHora_noticia_str(String hora_noticia_str) throws ParseException {
SimpleDateFormat sdf = new SimpleDateFormat("HH:mm:ss");
// String w_hms_atual = sdf.format(new java.util.Date());
java.util.Date datax = sdf.parse(hora_noticia_str);
java.sql.Time w_hora_noticia = new Time(datax.getTime());
System.out.println("2222#w_hora_noticia= " + w_hora_noticia);
setHora_noticia(w_hora_noticia);
// return hora_noticia_str;
this.hora_noticia_str = hora_noticia_str;
}
public Time getHora_noticia() {
return hora_noticia;
}
public void setHora_noticia(java.sql.Time hora_noticia) {
/* SimpleDateFormat sdf = new SimpleDateFormat("HH:mm:ss");
// String w_hms_atual = sdf.format(new java.util.Date());
java.util.Date datax = sdf.parse(hora_noticia_str);
java.sql.Time w_hora_noticia = new Time(datax.getTime()); */
this.hora_noticia = hora_noticia;
}
public String getData_noticia_DMA() throws ParseException {
SimpleDateFormat formatador = new SimpleDateFormat("dd/MM/yyyy");
String wdt_dd_mm_aaaa = formatador.format(data_noticia_DMA);
//System.out.println("2222#wdt_dd_mm_aaaa= " + wdt_dd_mm_aaaa + "# data_amd= " + data_noticia_AMD);
setData_noticia_DMA(wdt_dd_mm_aaaa);
return data_noticia_DMA;
}
public void setData_noticia_DMA(String data_noticia_DMA) throws ParseException {
DateFormat wf_dma1 = new SimpleDateFormat("dd/MM/yyyy");
java.sql.Date Data_amd = new java.sql.Date(wf_dma1.parse(data_noticia_DMA).getTime());
String Data_YMD_str = new SimpleDateFormat("yyyy-MM-dd").format(Data_amd);
System.out.println("222#data_ymd_str= " + Data_YMD_str + "# data_amd= " + Data_amd);
setData_noticia_AMD(Data_amd);
this.data_noticia_DMA = data_noticia_DMA;
}
public java.util.Date getData_noticia_AMD() {
return data_noticia_AMD;
}
public void setData_noticia_AMD(Date data_noticia_AMD) {
this.data_noticia_AMD = data_noticia_AMD;
}
public static Time getW_hora_atual() throws ParseException {
SimpleDateFormat sdf = new SimpleDateFormat("HH:mm:ss");
String w_hms_atual = sdf.format(new java.util.Date());
java.util.Date data = sdf.parse(w_hms_atual);
java.sql.Time w_hora_atual = new Time(data.getTime());
return w_hora_atual;
}
// public void setAppointmentDate(String appointmentDate) {
// DateFormat df = new SimpleDateFormat("dd-MM-yyyy");
// this.appointmentDate = df.parse(appointmentDate);
// }
}