getOutputStream
1 posts in topic
Flat View  Flat View
TOPIC ACTIONS:
 

Posted By:   giorgio_bellinger
Posted On:   Wednesday, July 2, 2003 03:04 AM

I have the following problem. This error (one time yes, one time no ): java.lang.IllegalStateException: getOutputStream() has already been called is produced by this code: ______________ type="text/css" /> <%@ page language="java" import="java.sql.*" %> <%@ page import="com.lowagie.text.*" %> <%@ page import="java.io.*" %> <%@ page import="java.awt.*" %> <%@ page import="com.lowagie.text.pdf.*" %> <%@ page import="com.lowagie.text.pdf.PdfWri   More>>

I have the following problem.

This error (one time yes, one time no ):



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



is produced by this code:

______________






type="text/css" />






<%@ page language="java" import="java.sql.*" %>

<%@ page import="com.lowagie.text.*" %>

<%@ page import="java.io.*" %>

<%@ page import="java.awt.*" %>

<%@ page import="com.lowagie.text.pdf.*" %>

<%@ page import="com.lowagie.text.pdf.PdfWriter"%>

<%@ page import="com.lowagie.text.pdf.ColumnText"%>

<%@ page import="com.lowagie.text.pdf.PdfContentByte"%
>
<%@ page import="com.lowagie.text.pdf.BaseFont"%>

<%@ page autoFlush="false"%>

<%



Class.forName("oracle.jdbc.driver.OracleDriver");


String stId = request.getParameter("Licenza");

String stFamiglia = request.getParameter("Famiglia");

String stMarchio = request.getParameter("Marchio");

String stMatricola = request.getParameter("Matricola");

String stCliente = request.getParameter("Cliente");

String stLimit = request.getParameter("Limitazione");

String stTipLimit = request.getParameter("TipoLimitazione");


String stSql = "SELECT DESCRITTOREPROTEZ.DOS_WIN, DESCRITTOREPROTEZ.ID_PRG, DESCRITTOREPROTEZ.STANDARD, FAMIGLIEPRG.DESCRFAMIGLIA, " +

....

....



if (!stId.equals("")){

stSql = stSql + " AND protezioni.ID_PROT = " + stId + " ";

}


...........

...........

............



stSql = stSql + stOrderby;


Connection dbconn = DriverManager.getConnection("jdbc:oracle:thin:@10.39.1.251:1521:silcadb","gescli","ges2000");


Statement statement = dbconn.createStatement();


ResultSet rs = statement.executeQuery(stSql);


int i = 0;

String stClass = "";

String stComm, stSys;


// java.awt.Color border = new java.awt.Color(0xED, 0x1C, 0x24);

java.awt.Color border = new java.awt.Color(0, 0, 0);
com.lowagie.text.Font font1 = new com.lowagie.text.Font(com.lowagie.text.Font.HELVETICA, 10, com.lowagie.text.Font.NORMAL, border);

com.lowagie.text.Font font2 = new com.lowagie.text.Font(com.lowagie.text.Font.HELVETICA, 8, com.lowagie.text.Font.NORMAL, border);

com.lowagie.text.Font font3 = new com.lowagie.text.Font(com.lowagie.text.Font.HELVETICA, 6, com.lowagie.text.Font.NORMAL, border);

Document document = new Document(PageSize.A4.rotate(), 20, 20, 15, 15);

// document.addSubject("Test");


java.io.ByteArrayOutputStream baos = new java.io.ByteArrayOutputStream();


PdfWriter writer = PdfWriter.getInstance(document, baos);
document.open();


//table


Table table = new Table(10);

int[] widths = {5, 10, 15, 25, 10, 10, 5, 3, 15, 2};

table.setWidths(widths);

table.setAlignment(0);

float width = 100;

table.setWidth(width);


//widths = (10,10,10,90);


table.setBorderWidth(0);

table.setCellpadding(1);

// table.setCellspacing(10);


//header

Cell cell = new Cell("Codici protetti");

cell.setHeader(true);


cell.setColspan(10);

table.addCell(cell);


cell = new Cell(" ");

cell.setColspan(10);

// cell.setBorderColor(new Color(255, 0, 0));

table.addCell(cell);


table.endHeaders();



while (rs.next()){


if (rs.getString("MAT_MAC") == null) {
stComm = rs.getString("ID_PROT");

}

else {

stComm = rs.getString("MAT_MAC");

}


if (rs.getString("DOS_WIN").equals("0"))
stSys = "DOS";

else v
stSys="WIN";


table.addCell(new Paragraph("" + stComm + " ", font3));

table.addCell(new Paragraph("" + rs.getString("RAG_SOCIALE") + " ", font3));

...

...

}


document.add(table);


document.close();


// response.reset();

response.setContentType("application/pdf");

response.setContentLength(baos.size());

ServletOutputStream myOut = response.getOutputStream();

baos.writeTo(myOut);

myOut.flush();


// try to resolve

// baos.reset();

// baos.close();

// myOut.close();

// myOut = null;

// response.flushBuffer();


dbconn.close();


%>







______________


Can you help me.



Thanks


Giorgio Bellinger

   <<Less

Re: getOutputStream

Posted By:   Anonymous  
Posted On:   Wednesday, July 2, 2003 05:33 AM

You should really write this as a servlet especially when all you have is java code coded here. A JSP is supposed to be for ascii/text data. This is why the implicit object out is created for the JSP developer by default (and is of type JspWriter). The specification is quite clear on this.
About | Sitemap | Contact