Jasper-reports:已经为此响应调用了getOutputStream()

时间:2015-05-18 19:19:10

标签: jsp jasper-reports outputstream illegalstateexception

在我的java web应用程序中,我想在输入他的id时打印用户的信息,我使用了插件jasperreport和netbeans,问题是当我编译和预览报告时它工作,但当我使用我的page html我有一个空页面,这个错误:

java.lang.IllegalStateException: getOutputStream() has already been called for this response

page.html中

  <form action="info.jsp">
   <input type="text"  name="id" >
  </form>

info.jsp

  <body>
    <% 

  int id=Integer.parseInt(request.getParameter("id"));

 try{
 Class.forName("com.mysql.jdbc.Driver");
 Connection conn=DriverManager.getConnection("jdbc:mysql://localhost/test","root","");
Statement st = conn.createStatement();
File reportFile = new File(application.getRealPath("//info.jasper"));
Map param=new HashMap();
param.put("id", id);
 byte[]bytes=JasperRunManager.runReportToPdf(reportFile.getPath(),param,conn);
  response.setContentType("application/pdf");
  response.setContentLength(bytes.length);
  ServletOutputStream outStream=response.getOutputStream();
  outStream.write(bytes,0,bytes.length);
  outStream.flush();
  outStream.close();
  }catch(Exception ex){
  ex.printStackTrace();
  }      

    %>

0 个答案:

没有答案