Boa tarde galera.
Estou criando uma aplicação, só que quando eu vou emitir o relatório dos produtos
cadastrados da erro 500.Estou utilizando um “gravar.jsp” para amazenar no Vector e depois
salvar da session, para eu resgatar quando quiser fazr relatorio. Mas não sai desse erro… :shock:
relatorio.jsp
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<%@page import="java.util.Vector"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<%
Vector dados =(Vector)session.getAttribute("cadastros");
if(dados == null) new Vector();
%>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Relatorio Produtos</title>
</head>
<body>
<h2 align="center">Relatorio de Produtos Cadastrados</h2>
<%
for(int i = 0; i < dados.size(); i++)
out.println(dados.get(i));
%>
</body>
</html>
gravar.jsp
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<%@ page import="java.util.*,web.wer.com.br.Produto" %>
<%@page errorPage="erro.jsp" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<%
Vector dados = (Vector)session.getAttribute("cadastros");
if(dados == null) dados = new Vector();
Produto prod = new Produto();
prod.setNome(request.getParameter("nome"));
prod.setCodigo(Integer.parseInt(request.getParameter("codigo")));
prod.setValor(Double.parseDouble(request.getParameter("valor")));
dados.add(prod);
session.setAttribute("cadastros ", dados);
%>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Gravando Produto</title>
</head>
<body>
<h2 align="center">Gravado Com Sucesso!</h2>
<table align="center">
<tr>
<td><input type="button" value="Voltar" onclick="document.location='index.jsp'"></td>
<td><input type="button" value="Relatorio" onclick="document.location='relatorio.jsp'"></td>
</tr>
</table>
</body>
</html>
index.jsp
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<%@page import="web.wer.com.br.Produto" %>
<!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>Coleção de JavaBens</title>
</head>
<body>
<h2 align="center">Cadastro de Produto</h2><br>
<form action="gravar.jsp" method="post">
<table align="center">
<tr>
<td>Nome:</td>
<td><input type="text" name="nome" size="30"></td>
</tr>
<tr>
<td>Codigo:</td>
<td><input type="text" name="codigo" size="3"></td>
</tr>
<tr>
<td>Valor:</td>
<td><input type="text" name="valor" size="6"></td>
</tr>
<tr>
<td><input type="submit" value="Gravar"></td>
<td><input type="button" value="Relatorio" onclick="document.location='relatorio.jsp'"></td>
<td></td>
</tr>
</table>
</form>
</body>
</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: An exception occurred processing JSP page /relatorio.jsp at line 19
16: <h2 align="center">Relatorio de Produtos Cadastrados</h2>
17: <%
18:
19: for(int i = 0; i < dados.size(); i++)
20: out.println(dados.get(i));
21: %>
22: </body>
Stacktrace:
org.apache.jasper.servlet.JspServletWrapper.handleJspException(JspServletWrapper.java:521)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:430)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:313)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:260)
javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
root cause
java.lang.NullPointerException
org.apache.jsp.relatorio_jsp._jspService(relatorio_jsp.java:72)
org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70)
javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:388)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:313)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:260)
javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
note The full stack trace of the root cause is available in the Apache Tomcat/6.0.33 logs.
Apache Tomcat/6.0.33