Quickly glancing at your code I believe you need to return null such as
ostr.close();
return null;
HTH,
Glenn
Karthika L V somayajula [EMAIL PROTECTED]
14/06/2005 10:35 AM
Please respond to
Struts Users Mailing List user@struts.apache.org
To
user@struts.apache.org
cc
Subject
reponse commited
I hope am into the right group
I have a problem with downloading files using struts.
I am using J2SDK 1.4.2_06
Struts 1.2.4
Jboss 4.0.1RC2
My download Action is :
public ActionForward executeAction( ActionMapping mapping,
ActionForm form,
HttpServletRequest
request,
HttpServletResponse response
) throws
BusinessDelegateException,IOException
{
ReportGenerateForm rform = (ReportGenerateForm) form ;
ActionForward forward = mapping.findForward(Constant.DOWNLOAD_REPORT);
ReportGenerateDelegate reportGenerateDelegate = new
ReportGenerateDelegate();
int empId = getIntranetUser( request ).getEmployeeID();
String reportId = request.getParameter(rid);
String companyId =
String.valueOf(getIntranetUser(request).getCompanyId());
String companyName = getIntranetUser(request).getCompanyName();
String projectId = Constant.STRING_ZERO;
String projectName = Constant.BLANK;
String fn = reportGenerateDelegate.getFileName(reportId);
//prepend employee Id to file Name
StringBuffer file = new StringBuffer(String.valueOf(empId));
file.append(Constant.FILENAME_SEPERATOR_LITERAL).append(fn);
String fileName = new String(file);
// scrub the company name
ArrayList arr = new ArrayList();
arr.add(companyName);
arr = (ArrayList)rform.validateData( arr ) ;
String scrubbedCompanyName = (String)arr.get(0);
IntranetLogger.logInfo(Scrubbed Comapny Name is +scrubbedCompanyName);
arr = null;
if( fileName != null )
{
File fname = new File(fileName);
FileUpload fileUpload = new FileUpload();
String default_folder = Constant.REPORTS_FOLDER;
String relativePath = FileUpload.getPathName
(companyId,scrubbedCompanyName,projectId,projectName,default_folder);
// append relative path to the Document Root defined in
FileUpload.properties file
String downloadPath = FileUpload.getPath(Constant.BLANK) + relativePath;
IntranetLogger.logInfo(In DownloadReportAction FULL PATH of the
file. + downloadPath);
FileInputStream istr = null ;
OutputStream ostr = null;
try
{
IntranetLogger.logInfo(TOTAL DOWNLOAD PATH IS: +(downloadPath +
fname));
istr = new FileInputStream( downloadPath + fname);
IntranetLogger.logInfo(File available? + istr.available());
IntranetLogger.logInfo(File name +fileName);
if ( istr.available() == 0 )
{
IntranetLogger.logInfo(File Not available + fileName);
addErrors(error.document.empty, fileName,request);
}
else
{
// set content type of the response object to
Application/octet-stream. By setting this
// we can download any type of file like txt, pdf, doc, xls etc
response.setContentType(APPLICATION/OCTET-STREAM);
response.setHeader(Content-Disposition, attachment;filename=\ +
fname.getName() +\;);
IntranetLogger.logInfo(Reponse content type set);
// the following line is required to send a pop-up open-save-cancel
file dialog box
ostr = response.getOutputStream();
int bytesRead = 0;
byte[] buffer = new byte[8192];
while( (bytesRead = istr.read(buffer, 0, 8192)) != -1)
{
ostr.write(buffer, 0, bytesRead);
}
//ostr.flush();
istr.close();
ostr.close();
addMessages(download.success, fileName, request);
}
}//try
catch(Exception ex)
{
IntranetLogger.logInfo(Error in flushing out the Streams:
+ex.toString());
// if file already exists, then gives the proper messeage.
addErrors(error.document.empty, fileName,request);
//forward = mapping.findForward( Constant.GENERATE_REPORT) ;
forward = mapping.findForward(Constant.DOWNLOAD_REPORT);
}
finally
{
try
{
istr.close();
ostr.close();
}
catch(Exception ex)
{
IntranetLogger.logInfo(Major Error Releasing Streams: +ex.toString());
addErrors(error.document.empty, fileName,request);
}
}
try
{
response.flushBuffer();
}
catch(Exception ex)
{
IntranetLogger.logInfo(Error flushing the Response: +ex.toString());
addErrors(error.document.empty, fileName, request);
}
}
return forward;
}
My jsp includes
meta http-equiv=Content-Type content=text/html; charset=iso-8859-1
I get the list of file name with links in my JSP, one of which I click
i should get a open, save file dialog box
Now, when i click on the the filename on link I get the exception
StandardWrapperValve[action]:
cannot forward,reponse already commited
Please reply if you find mistakes or errors in my action
Thank you advance
Karthika
-
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]