| Author |
Download using Structs Portlet throws IllegalStateException Exception
|
|
|
| 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.
| |
|
| 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.
>
>
>
>
| |
|
| 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.
>
>
>
>
| |
|
|
|
|