日期:2014-05-17  浏览次数:20693 次

求高人指点。jas调用jasperreprot报表出现内存溢出
<%@ page contentType="application/pdf;charset=UTF-8"%>
<%@ page import="net.sf.jasperreports.engine.*" %>
<%@ page import="java.util.*" %>
<%@ page import="java.io.*" %>
<%@ page import="java.sql.*" %>
<%
 //报表编译之后生成的.jasper文件的存放位置
 File reportFile = new File(this.getServletContext().
getRealPath("/report/studnetinfo.jasper"));
  
 String url="jdbc:mysql://localhost:3306/exam";
 Class.forName("com.mysql.jdbc.Driver");
 Map parameters = new HashMap();
 //"SQLSTR"是报表中定义的一个参数名称,其类型为String 型
 parameters.put("phone",
 "select * from eusers");
 Connection conn = DriverManager.getConnection(url,
"root", "root");
  
 byte[] bytes=JasperRunManager.
runReportToPdf(reportFile.getPath(),parameters,conn);
  
 response.setContentType("application/pdf");
 response.setContentLength(bytes.length);
  
 ServletOutputStream outStream = response.getOutputStream();
 outStream.write(bytes,0,bytes.length);
 outStream.flush();
 outStream.close();
 out.clear();
 out = pageContext.pushBody();
%>



org.apache.jasper.JasperException: javax.servlet.ServletException: java.lang.OutOfMemoryError: PermGen space
org.apache.jasper.servlet.JspServletWrapper.handleJspException(JspServletWrapper.java:486)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:398)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:342)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:267)
javax.servlet.http.HttpServlet.service(HttpServlet.java:717)


root cause 

javax.servlet.ServletException: java.lang.OutOfMemoryError: PermGen space
org.apache.jasper.runtime.PageContextImpl.doHandlePageException(PageContextImpl.java:852)
org.apache.jasper.runtime.PageContextImpl.handlePageException(PageContextImpl.java:781)
org.apache.jsp.index_jsp._jspService(index_jsp.java:96)
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:374)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:342)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:267)
javax.servlet.http.HttpServlet.service(HttpServlet.java:717)


root cause 

java.lang.OutOfMemoryError: PermGen space




------解决方案--------------------
你在上面设置了字节流,这个占用了大量的内存,需要及时释放不然就会内存溢出,加上这句就好了bytes=null;