Hi,

I've created a struts2 application that creates text file and displays the 
file download dialog for the user to open or save it.
It works fine if the user opens or saves it, but if the user closes the 
file download dialog the program logs the following error:

Servlet failed with Exception
java.lang.IllegalStateException: Response already committed
        at 
weblogic.servlet.internal.ServletResponseImpl.objectIfCommitted(Servl
etResponseImpl.java:1422)
        at 
weblogic.servlet.internal.ServletResponseImpl.sendError(ServletRespon
seImpl.java:580)
        at 
org.apache.struts2.dispatcher.Dispatcher.sendError(Dispatcher.java:77
1)
        at 
org.apache.struts2.dispatcher.Dispatcher.serviceAction(Dispatcher.jav
a:506)
        at 
org.apache.struts2.dispatcher.FilterDispatcher.doFilter(FilterDispatc
her.java:395)
        Truncated. see log file for complete stacktrace
>

My struts.xml file code is as follows:

<action name="AdmExport" class="ConfigAction" method="export">
            <result name="success" type="stream"> 
            <param name="contentType">application/octet-stream</param>
                <param name="inputName">inputStream</param>
                <param 
name="contentDisposition">attachment;filename="tempExport.txt"</param>
                <param name="bufferSize">1024</param> 
           </result>
        </action>
 
My action class code is as follows:

import org.apache.struts2.interceptor.SessionAware;
import com.opensymphony.xwork2.ActionContext;
import com.opensymphony.xwork2.ActionSupport;


public class ConfigAction extends ActionSupport  implements SessionAware
{

public void setInputStream(InputStream inputStream) {
                this.inputStream = inputStream;
        }
public InputStream getInputStream() {
                return inputStream;
        }

public String export() throws Exception {
 
                try
                { 
                  // code to create tempExport.txt file 
 
                        File exportFile = new File("./tempExport.txt");
                        setInputStream(new FileInputStream(exportFile));
                        exportFile.delete();
                }
                catch (Exception ex)
                { 
                        ex.printStackTrace();
                }
 
                return SUCCESS;
        } 
}

Any ideas as how to fix the issue will be greatly appreciated.

Thanks,

Svetlana Roslyakova ·  The Bank of New York Mellon 
Regulatory Systems · Tel 212.815.8043 · svetlana.roslyak...@bnymellon.com

The information contained in this e-mail, and any attachment, is confidential 
and is intended solely for the use of the intended recipient. Access, copying 
or re-use of the e-mail or any attachment, or any information contained 
therein, by any other person is not authorized. If you are not the intended 
recipient please return the e-mail to the sender and delete it from your 
computer. Although we attempt to sweep e-mail and attachments for viruses, we 
do not guarantee that either are virus-free and accept no liability for any 
damage sustained as a result of viruses. 

Please refer to http://disclaimer.bnymellon.com/eu.htm for certain disclosures 
relating to European legal entities.

Reply via email to