Solucionado (ver solução)
Solucionado
(ver solução)
3
respostas

Dúvida no Ex. 1 da Aula 4 - Enviando dados para a JSP

Estou tendo a seguinte erro ao fazer a requisição:

org.apache.jasper.JasperException: javax.servlet.ServletException: javax.servlet.jsp.JspException: In <formatNumber>, value attribute can not be parsed into java.lang.Number: "${conta.valor}"
    org.apache.jasper.servlet.JspServletWrapper.handleJspException(JspServletWrapper.java:585)
    org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:455)
    org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:395)
    org.apache.jasper.servlet.JspServlet.service(JspServlet.java:339)
    javax.servlet.http.HttpServlet.service(HttpServlet.java:731)
    org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)
    org.springframework.web.servlet.view.InternalResourceView.renderMergedOutputModel(InternalResourceView.java:168)
    org.springframework.web.servlet.view.AbstractView.render(AbstractView.java:303)
    org.springframework.web.servlet.DispatcherServlet.render(DispatcherServlet.java:1244)
    org.springframework.web.servlet.DispatcherServlet.processDispatchResult(DispatcherServlet.java:1027)
    org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:971)
    org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:893)
    org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:970)
    org.springframework.web.servlet.FrameworkServlet.doGet(FrameworkServlet.java:861)
    javax.servlet.http.HttpServlet.service(HttpServlet.java:624)
    org.springframework.web.servlet.FrameworkServlet.service(FrameworkServlet.java:846)
    javax.servlet.http.HttpServlet.service(HttpServlet.java:731)
    org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)
root cause

javax.servlet.ServletException: javax.servlet.jsp.JspException: In <formatNumber>, value attribute can not be parsed into java.lang.Number: "${conta.valor}"
    org.apache.jasper.runtime.PageContextImpl.doHandlePageException(PageContextImpl.java:912)
    org.apache.jasper.runtime.PageContextImpl.handlePageException(PageContextImpl.java:845)
    org.apache.jsp.WEB_002dINF.jsp.conta.lista_jsp._jspService(lista_jsp.java:115)
    org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70)
    javax.servlet.http.HttpServlet.service(HttpServlet.java:731)
    org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:432)
    org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:395)
    org.apache.jasper.servlet.JspServlet.service(JspServlet.java:339)
    javax.servlet.http.HttpServlet.service(HttpServlet.java:731)
    org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)
    org.springframework.web.servlet.view.InternalResourceView.renderMergedOutputModel(InternalResourceView.java:168)
    org.springframework.web.servlet.view.AbstractView.render(AbstractView.java:303)
    org.springframework.web.servlet.DispatcherServlet.render(DispatcherServlet.java:1244)
    org.springframework.web.servlet.DispatcherServlet.processDispatchResult(DispatcherServlet.java:1027)
    org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:971)
    org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:893)
    org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:970)
    org.springframework.web.servlet.FrameworkServlet.doGet(FrameworkServlet.java:861)
    javax.servlet.http.HttpServlet.service(HttpServlet.java:624)
    org.springframework.web.servlet.FrameworkServlet.service(FrameworkServlet.java:846)
    javax.servlet.http.HttpServlet.service(HttpServlet.java:731)
    org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)
root cause

java.lang.NumberFormatException: For input string: "${conta.valor}"
    sun.misc.FloatingDecimal.readJavaFormatString(FloatingDecimal.java:2043)
    sun.misc.FloatingDecimal.parseDouble(FloatingDecimal.java:110)
    java.lang.Double.parseDouble(Double.java:538)
    java.lang.Double.valueOf(Double.java:502)
    org.apache.taglibs.standard.tag.common.fmt.FormatNumberSupport.doEndTag(FormatNumberSupport.java:193)
    org.apache.jsp.WEB_002dINF.jsp.conta.lista_jsp._jspx_meth_fmt_005fformatNumber_005f0(lista_jsp.java:197)
    org.apache.jsp.WEB_002dINF.jsp.conta.lista_jsp._jspx_meth_c_005fforEach_005f0(lista_jsp.java:146)
    org.apache.jsp.WEB_002dINF.jsp.conta.lista_jsp._jspService(lista_jsp.java:96)
    org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70)
    javax.servlet.http.HttpServlet.service(HttpServlet.java:731)
    org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:432)
    org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:395)
    org.apache.jasper.servlet.JspServlet.service(JspServlet.java:339)
    javax.servlet.http.HttpServlet.service(HttpServlet.java:731)
    org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)
    org.springframework.web.servlet.view.InternalResourceView.renderMergedOutputModel(InternalResourceView.java:168)
    org.springframework.web.servlet.view.AbstractView.render(AbstractView.java:303)
    org.springframework.web.servlet.DispatcherServlet.render(DispatcherServlet.java:1244)
    org.springframework.web.servlet.DispatcherServlet.processDispatchResult(DispatcherServlet.java:1027)
    org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:971)
    org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:893)
    org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:970)
    org.springframework.web.servlet.FrameworkServlet.doGet(FrameworkServlet.java:861)
    javax.servlet.http.HttpServlet.service(HttpServlet.java:624)
    org.springframework.web.servlet.FrameworkServlet.service(FrameworkServlet.java:846)
    javax.servlet.http.HttpServlet.service(HttpServlet.java:731)
    org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)

código do Controller:

@RequestMapping(value="/conta", method=RequestMethod.GET)
    public ModelAndView lista(){
        Conta c1 = new Conta();
        c1.setDataPagamento(Calendar.getInstance());
        c1.setDescricao("Testando");
        c1.setId(10L);
        c1.setPaga(true);
        c1.setValor(500.99);
        c1.setTipo(TipoDaConta.ENTRADA);

        Conta c = new Conta();
        c.setDataPagamento(Calendar.getInstance());
        c.setDescricao("Testando");
        c.setId(10L);
        c.setPaga(true);
        c.setValor(500.99);
        c.setTipo(TipoDaConta.ENTRADA);

        List<Conta> contas = Arrays.asList(c,c1);

        ModelAndView mv = new ModelAndView("conta/lista");
        mv.addObject("contas", contas);

        return mv;
    }

código da view

<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
   <%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
   <%@ taglib uri="http://java.sun.com/jsp/jstl/fmt" prefix="fmt" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Insert title here</title>
</head>
<body>

    <table>
        <tr>
            <th>ID</th>
            <th>Descrição</th>
            <th>Tipo</th>
            <th>Valor</th>
            <th>Paga?</th>
            <th>Data Pagamento</th>
        </tr>
        <c:forEach items="${contas}" var="conta">
            <tr>
            <td>${conta.id}</td>
            <td>${conta.descricao}</td>
            <td>${conta.tipo}</td>
            <td><fmt:formatNumber type="currency" value="${conta.valor}"/></td>
            <td>
                <c:if test="${conta.paga eq true}">
                    Sim
                </c:if>
                <c:if test="${conta.paga eq false}">
                    Não
                </c:if>
            </td>
            <td><fmt:formatDate value="${conta.dataPagamento.time}" pattern="dd/MM/yyyy"/></td>
            </tr>            
        </c:forEach>

    </table>

</body>
</html>
3 respostas

troquei para

  <%@ taglib uri="http://java.sun.com/jstl/core" prefix="c" %>
   <%@ taglib uri="http://java.sun.com/jstl/fmt" prefix="fmt" %>

funcionou parcialmente, imprimiu da seguinte maneira:

ID Descrição Tipo Valor Paga? Data Pagamento ${conta.id} ${conta.descricao} ${conta.tipo} R$ 500,99 Sim 16/12/2015 ${conta.id} ${conta.descricao} ${conta.tipo} R$ 500,99 Sim 16/12/2015

solução!

Consegui corrigir e agora esta funcionando corretamente. O problema era o arquivo web.xml, eu estava utilizando a definição gerada pelo Maven, fiz o teste alterando para:

<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.com/xml/ns/javaee" xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" id="WebApp_ID" version="2.5">

e deu certo! :D

Oi Jorge,

Que bom que conseguiu resolver o problema :)

Bons estudos!