tomcat-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Yasir" <ya...@netlinksoft.net>
Subject Please reply--Important print writer problem.
Date Mon, 30 Dec 2002 13:40:24 GMT
Hi Friends,
I am receiving the sam eproblem which you have put on the site.I am following MVC architecture
and working with IBM WPOrtal server.I have my JSP packaged within the par file(PORTLET ARCHIVE).I
have a code in my JSP which writes some zip content to the browser using servletoutput stream
The aim is to download the zip file to the client machine my invoking the browsers default
download box.This works fine if i have the JSP outside the PAR file but when i have this JSP
inside the par it gives the exception.
java.lang.IllegalStateException Writer has already been obtained.
Please let me know the solution ASAP.Its important for me.
pasted below is the piece of code i am using in the jsp

<% 

// Create a object of CreateZip

CreateZip createZip = new CreateZip();


// It stores Report Path.

String reportPath = "C:/www/web-data/fieldconnect/llreports/YASIR.txt";

// Create a object of PrintWriter

PrintWriter printWriter = new PrintWriter(new FileOutputStream(new File(reportPath)));


printWriter.print("WritWriWritWWrWWriting data to text file...Writing data to text file...riting
data to text file...Writing data to text file...Writing data to text file...Writing data to
text file...iting data to text file...Writing data to text file...riting data to text file...Writing
data to text file...ing data to text file...Writing data to text file...ting data to text
file...Writing data to text file...ing data to text file...Writing data to text file...Writing
data to text file...Writing data to text file...Writing data to text file...Writing data to
text file");

printWriter.flush();

printWriter.close();


// It stores path of text file

String path = "C:/www/web-data/fieldconnect/llreports/";

// It stores name of text file

String fileName = "YASIR.txt";


// making zip of text file generated 

createZip.makeZip(fileName,path);

String zipPath = "C:/www/web-data/fieldconnect/llreports/YASIR.zip";

File deleteZipFile = new File(zipPath);


int zipsize = (int)deleteZipFile.length();

byte abyte0[] = new byte[zipsize];

ByteArrayOutputStream ba = new ByteArrayOutputStream(zipsize);

File deleteTxtFile = new File(reportPath);

if (deleteTxtFile.exists()){

deleteTxtFile.delete();

}



//PrintWriter zipWriter = new PrintWriter(new FileOutputStream());

FileInputStream fileInputStream = new FileInputStream(zipPath);


BufferedInputStream bufferedinputstream = new BufferedInputStream(fileInputStream);


int i;

while((i = bufferedinputstream.read(abyte0)) != -1){ 

ba.write(abyte0,0,i);

}


bufferedinputstream.close();

HttpServletResponse sResponse = (HttpServletResponse)((PortletResponseImpl)response).getServletResponse();

sResponse.setContentType("application/zip");

sResponse.setContentLength(ba.size());

sResponse.setHeader("Content-Type","application/octet-stream");

sResponse.setHeader("Content-Disposition","attachment; filename=\"YASIR.zip\"");

if (ba != null) {

ServletOutputStream sout = sResponse.getOutputStream();


ba.writeTo(sout);


ba.flush();

ba.close();

sout.close();

}



if (deleteZipFile.exists()){

deleteZipFile.delete();

}

%>


Thanks,
Yasir.

Mime
  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message