You have already sent a response to the browser by writing to the output
stream, hence the error created by struts.
I do something very similar in my application, except I stuck the file
sending in a normal servlet as it doesn't need/use any struts
functionality and there's no action to forward on to. Essentially just
implement the code you already have in the service() method of a servlet.
Paul
------------------------------------------------------------
Global Equity Derivatives Technology
Deutsche Bank [/]
Office +44 (0)20 754 55458
Mobile +44 (0)7736 299483
Fax +44 (0)20 7547 2752
------------------------------------------------------------
"Vasudevrao Gupta" <[EMAIL PROTECTED]>
03/03/2004 14:57
Please respond to "Struts Users Mailing List"
To: "'Struts Users Mailing List'" <[EMAIL PROTECTED]>, "'Satya
Narayan Dash'" <[EMAIL PROTECTED]>
cc:
Subject: Viewing .pdf files usign struts frames work..
Hi All,
I am trying to view a pdf file using struts frame work..
I am able to view the file ,but it throws an illegalStateException as
struts
forward the request after I send the output stream.
Below is the action mapping:
<action name="enquiryFormBean"
path="/viewScannedFile"
scope="request"
type="com.rwe.thameswater.els.enquiry.action.ViewScannedFileRefAction"input=
"/screens/enquiry/jsp/ADS_ELS_CreateEnquiry.jsp"
validate="true">
<forward name="SUCCESS"
path="/screens/enquiry/jsp/ADS_ELS_ScannedFile.jsp">
</forward>
</action>
below is the action class execute() method:
try {
MessageResources resource
= this.getResources(request);
String scannedFileFolder
= (String)
resource.getMessage(ELSEnquiryConstantsIF.SCANNED_FILE_LOCATN);
System.out.println("scannedFileFolder>>"+scannedFileFolder);
String scannedFileExtn =
(String)
resource.getMessage(ELSEnquiryConstantsIF.SCANNED_FILE_EXTN);
System.out.println("scannedFileExtn>>"+scannedFileExtn);
String
scannedFileLocation = scannedFileFolder +
request.getParameter("scannedFileReference") + scannedFileExtn;
System.out.println("scannedFileLocation>>"+scannedFileLocation);
String contentType =
(String)
resource.getMessage(ELSEnquiryConstantsIF.SCANNED_FILE_CONTENT);
System.out.println("contentType>>"+contentType);
response.setContentType(contentType);
File pdfFile = new
File(scannedFileLocation);
response.setContentLength((int) pdfFile.length());
FileInputStream in = new
FileInputStream(pdfFile);
request.setAttribute("FILE",in);
OutputStream out =
response.getOutputStream();
byte[] buf = new
byte[4096];
int count = 0;
while ((count =
in.read(buf)) >= 0) {
out.write(buf, 0, count);
}
out.flush();
in.close();
out.close();
} catch (Exception e) {
// Report the error using
the appropriate name and ID.
System.out.println("Exception found while viewing>>"+e);
errors.add("name", new
ActionError("id"));
}
return (mapping.findForward("SUCCESS"));
}
Please suggest me anyother alternative using the struts framework
Confidentiality Notice
The information contained in this electronic message and any attachments
to this message are intended
for the exclusive use of the addressee(s) and may contain confidential or
privileged information. If
you are not the intended recipient, please notify the sender at Wipro or
[EMAIL PROTECTED] immediately
and destroy all copies of this message and any attachments.
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]