Using PrintWriter and OutputStream

前端 未结 4 1626
不思量自难忘°
不思量自难忘° 2021-01-13 08:33

I am creating a project with struts and I have a problem using Jasper IReports. I want to export some info into a pdf file and I keep getting the java.lang.IllegalStateExcep

4条回答
  •  梦毁少年i
    2021-01-13 08:40

    Would be useful to see the stack trace.

    You might try running a sanity check first though: Modify that code to simply write a static string (hello world) to the ServletOutputStream and set content type to text/html. As that should work fine:

    public void handle(HttpServletResponse res, Connection connection, String path)throws Exception{
    ServletOutputStream out = null;
    try {
        byte[] bytes = "hello world".getBytes();
        res.setContentType("text/html");
        res.setContentLength(bytes.length);
        out = res.getOutputStream();
        out.write(bytes, 0, bytes.length);
    } catch (Exception e) {
        e.printStackTrace();
    } finally {
        out.flush();
        out.close();
    }
    

    HTH

提交回复
热议问题