WebSphere Portal Server - Download using Structs Portlet throws IllegalStateException Exception

This is Interesting: Free IT Magazines  
Home > Archive > WebSphere Portal Server > April 2005 > Download using Structs Portlet throws IllegalStateException Exception





You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

Author Download using Structs Portlet throws IllegalStateException Exception

2005-04-08, 7:49 am

I am trying to implement the file download program using struct-portlet framework.
It is throwing IllegalStateException exception.
Below is the portion of code written in the final jsp page

try {
String filename = "C:\\temp\\faq.txt";

// set the http content type to "APPLICATION/OCTET-STREAM
response.setContentType("APPLICATION/OCTET-STREAM");

// initialize the http content-disposition header to
// indicate a file attachment with the default filename
// "faq.txt"
//String disHeader = "AttachmentFilename=\"faq.txt\"";

//response.setHeader ("Content-Disposition", disHeader);

// transfer the file byte-by-byte to the response object

File fileToDownload = new File(filename);
System.out.println("After Opening file");
FileInputStream fileInputStream = new
FileInputStream(fileToDownload);
System.out.println("After open the stream");
int i;

while ((i=fileInputStream.read())!=-1)
{
out.write(i);
}

fileInputStream.close();
out.close();
}catch(Exception e) // file IO errors
{
e.printStackTrace();
}

How to implement this file download program in the structs-portlet framwork?
Any suggetion will be highly appriciated.




Pim

2005-04-08, 7:49 am

Try not setting the response's contenttype. In portal you cannot write
anything to it.

regards,

Pim

manish_jha_kamal@rediffmail.com wrote:
> I am trying to implement the file download program using struct-portlet framework.
> It is throwing IllegalStateException exception.
> Below is the portion of code written in the final jsp page
>
> try {
> String filename = "C:\\temp\\faq.txt";
>
> // set the http content type to "APPLICATION/OCTET-STREAM
> response.setContentType("APPLICATION/OCTET-STREAM");
>
> // initialize the http content-disposition header to
> // indicate a file attachment with the default filename
> // "faq.txt"
> //String disHeader = "AttachmentFilename=\"faq.txt\"";
>
> //response.setHeader ("Content-Disposition", disHeader);
>
> // transfer the file byte-by-byte to the response object
>
> File fileToDownload = new File(filename);
> System.out.println("After Opening file");
> FileInputStream fileInputStream = new
> FileInputStream(fileToDownload);
> System.out.println("After open the stream");
> int i;
>
> while ((i=fileInputStream.read())!=-1)
> {
> out.write(i);
> }
>
> fileInputStream.close();
> out.close();
> }catch(Exception e) // file IO errors
> {
> e.printStackTrace();
> }
>
> How to implement this file download program in the structs-portlet framwork?
> Any suggetion will be highly appriciated.
>
>
>
>

Pim

2005-04-08, 7:49 am

Try not setting the response's contenttype. In portal you cannot write
anything to it.

regards,

Pim

manish_jha_kamal@rediffmail.com wrote:
> I am trying to implement the file download program using struct-portlet framework.
> It is throwing IllegalStateException exception.
> Below is the portion of code written in the final jsp page
>
> try {
> String filename = "C:\\temp\\faq.txt";
>
> // set the http content type to "APPLICATION/OCTET-STREAM
> response.setContentType("APPLICATION/OCTET-STREAM");
>
> // initialize the http content-disposition header to
> // indicate a file attachment with the default filename
> // "faq.txt"
> //String disHeader = "AttachmentFilename=\"faq.txt\"";
>
> //response.setHeader ("Content-Disposition", disHeader);
>
> // transfer the file byte-by-byte to the response object
>
> File fileToDownload = new File(filename);
> System.out.println("After Opening file");
> FileInputStream fileInputStream = new
> FileInputStream(fileToDownload);
> System.out.println("After open the stream");
> int i;
>
> while ((i=fileInputStream.read())!=-1)
> {
> out.write(i);
> }
>
> fileInputStream.close();
> out.close();
> }catch(Exception e) // file IO errors
> {
> e.printStackTrace();
> }
>
> How to implement this file download program in the structs-portlet framwork?
> Any suggetion will be highly appriciated.
>
>
>
>

Michael Harris

2005-04-08, 5:53 pm

Read this post with the title "Download in portlet + IllegalStateException"

news://news.software.ibm.com/d2rqkk$457s$1@news.boulder.ibm.com


Sponsored Links






Free braindumps | Software forum | Database administration forum

Copyright 2003 - 2008 webservertalk.com