You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by Andrew Hill <an...@gridnode.com> on 2004/03/03 15:50:26 UTC

RE: Viewing .pdf files usign struts frames work..

Since you are writing the response from your action you should return null
from execute() to indicate to struts that the response has been handled and
that it should not forward.

-----Original Message-----
From: Vasudevrao Gupta [mailto:vasudevrao.gupta@wipro.com]
Sent: Wednesday, 3 March 2004 22:58
To: 'Struts Users Mailing List'; 'Satya Narayan Dash'
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
Mailadmin@wipro.com immediately
and destroy all copies of this message and any attachments.

---------------------------------------------------------------------
To unsubscribe, e-mail: struts-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: struts-user-help@jakarta.apache.org



---------------------------------------------------------------------
To unsubscribe, e-mail: struts-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: struts-user-help@jakarta.apache.org