download file Error in struts2 action class

download file Error in struts2 action class

Hi,

i am using bellow block of code for download file :

public void downloadGreeting(String filename,HttpServletRequest request, HttpServletResponse response){
        String strPrefix = System.getProperty("astsoundsfolderoriginal");
        File requiredFile = new File(strPrefix + filename);
        System.out.println("requiredFile...."+requiredFile);
        if ( requiredFile.exists()) {
        try {
            response.setHeader("Content-Type", "application/wav; filename=" + filename);
            response.setHeader("Content-Disposition", "attachment; filename=" + filename);
            response.setHeader("Content-Length", "" + requiredFile.length());
                        **response.reset();**//even though i am using still i get the same problem
                       **response.resetBuffer();**//even though i am using still i get the same problem

                OutputStream os = response.getOutputStream();
                FileInputStream fis = new FileInputStream(requiredFile);
                int ch;
                while ( ( ch = fis.read() ) != -1 ) {
                    os.write(ch);
                    os.flush();

                }
                fis.close();
        } catch ( Exception ne ) {
                        System.out.println("Error in downloadGreeting()");
            }
    } else {
            System.out.println("file doesnot exist....");
    }
    }


while executing the following problem occured

**issue :**

WARNING: ApplicationDispatcher[/adminfive] PWC1231: Servlet.service() for servlet jsp threw exception
java.lang.IllegalStateException: PWC3991: getOutputStream() has already been called for this response
        at org.apache.catalina.connector.Response.getWriter(Response.java:705)
        at org.apache.catalina.connector.ResponseFacade.getWriter(ResponseFacade.java:225)
        at javax.servlet.ServletResponseWrapper.getWriter(ServletResponseWrapper.java:152)
        at org.apache.jasper.runtime.JspWriterImpl.initOut(JspWriterImpl.java:191)
        at org.apache.jasper.runtime.JspWriterImpl.flushBuffer(JspWriterImpl.java:184)
        at org.apache.jasper.runtime.JspWriterImpl.write(JspWriterImpl.java:405)
        at java.io.PrintWriter.write(PrintWriter.java:382)
        at org.apache.jasper.runtime.JspWriterImpl.flushBuffer(JspWriterImpl.java:185)
        at org.apache.jasper.runtime.JspWriterImpl.write(JspWriterImpl.java:458)
        at org.apache.jasper.runtime.JspWriterImpl.write(JspWriterImpl.java:471)
        at org.apache.jsp.layout.header_jsp._jspService(header_jsp.java from :437)
        at org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:111)
        at javax.servlet.http.HttpServlet.service(HttpServlet.java:848)
        at org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:403)
        at org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:492)
        at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:378)
        at javax.servlet.http.HttpServlet.service(HttpServlet.java:848)
        at org.apache.catalina.core.StandardWrapper.service(StandardWrapper.java:1534)
        at org.apache.catalina.core.ApplicationDispatcher.doInvoke(ApplicationDispatcher.java:787)
        at org.apache.catalina.core.ApplicationDispatcher.invoke(ApplicationDispatcher.java:649)
        at org.apache.catalina.core.ApplicationDispatcher.doInclude(ApplicationDispatcher.java:604)
        at org.apache.catalina.core.ApplicationDispatcher.include(ApplicationDispatcher.java:534)
        at org.apache.jasper.runtime.JspRuntimeLibrary.include(JspRuntimeLibrary.java:1015)
        at org.apache.jasper.runtime.PageContextImpl.include(PageContextImpl.java:700)
        at org.apache.tiles.jsp.context.JspTilesRequestContext.include(JspTilesRequestContext.java:103)
        at org.apache.tiles.jsp.context.JspTilesRequestContext.dispatch(JspTilesRequestContext.java:96)
        at org.apache.tiles.renderer.impl.UntypedAttributeRenderer.write(UntypedAttributeRenderer.java:61)
        at org.apache.tiles.renderer.impl.AbstractBaseAttributeRenderer.render(AbstractBaseAttributeRenderer.java:103)
        at org.apache.tiles.impl.BasicTilesContainer.render(BasicTilesContainer.java:659)
        at org.apache.tiles.impl.BasicTilesContainer.render(BasicTilesContainer.java:337)
        at org.apache.tiles.jsp.taglib.InsertAttributeTag.render(InsertAttributeTag.java:234)
        at org.apache.tiles.jsp.taglib.InsertAttributeTag.render(InsertAttributeTag.java:211)
        at org.apache.tiles.jsp.taglib.RenderTag.doEndTag(RenderTag.java:220)
        at org.apache.jsp.layout.baselayout_jsp._jspx_meth_tiles_insertAttribute_1(baselayout_jsp.java from :199)
        at org.apache.jsp.layout.baselayout_jsp._jspx_meth_s_div_0(baselayout_jsp.java from :160)
        at org.apache.jsp.layout.baselayout_jsp._jspService(baselayout_jsp.java from :95)
        at org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:111)
        at javax.servlet.http.HttpServlet.service(HttpServlet.java:848)
        at org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:403)
        at org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:492)
        at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:378)
        at javax.servlet.http.HttpServlet.service(HttpServlet.java:848)
        at org.apache.catalina.core.StandardWrapper.service(StandardWrapper.java:1534)
        at org.apache.catalina.core.ApplicationDispatcher.doInvoke(ApplicationDispatcher.java:787)
        at org.apache.catalina.core.ApplicationDispatcher.invoke(ApplicationDispatcher.java:649)
        at org.apache.catalina.core.ApplicationDispatcher.doInclude(ApplicationDispatcher.java:604)
        at org.apache.catalina.core.ApplicationDispatcher.include(ApplicationDispatcher.java:534)
        at org.apache.tiles.servlet.context.ServletTilesRequestContext.include(ServletTilesRequestContext.java:260)
        at org.apache.tiles.servlet.context.ServletTilesRequestContext.dispatch(ServletTilesRequestContext.java:220)
        at org.apache.tiles.renderer.impl.TemplateAttributeRenderer.write(TemplateAttributeRenderer.java:44)
        at org.apache.tiles.renderer.impl.AbstractBaseAttributeRenderer.render(AbstractBaseAttributeRenderer.java:103)
        at org.apache.tiles.impl.BasicTilesContainer.render(BasicTilesContainer.java:659)
        at org.apache.tiles.impl.BasicTilesContainer.render(BasicTilesContainer.java:678)
        at org.apache.tiles.impl.BasicTilesContainer.render(BasicTilesContainer.java:633)
        at org.apache.tiles.impl.BasicTilesContainer.render(BasicTilesContainer.java:322)
        at org.apache.struts2.views.tiles.TilesResult.doExecute(TilesResult.java:105)
        at org.apache.struts2.dispatcher.StrutsResultSupport.execute(StrutsResultSupport.java:186)
        at com.opensymphony.xwork2.DefaultActionInvocation.executeResult(DefaultActionInvocation.java:362)
        at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:266)
        at com.opensymphony.xwork2.interceptor.DefaultWorkflowInterceptor.doIntercept(DefaultWorkflowInterceptor.java:165)
        at com.opensymphony.xwork2.interceptor.MethodFilterInterceptor.intercept(MethodFilterInterceptor.java:87)
        at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:237)
        at com.opensymphony.xwork2.validator.ValidationInterceptor.doIntercept(ValidationInterceptor.java:252)
        at org.apache.struts2.interceptor.validation.AnnotationValidationInterceptor.doIntercept(AnnotationValidationInterceptor.java:68)
        at com.opensymphony.xwork2.interceptor.MethodFilterInterceptor.intercept(MethodFilterInterceptor.java:87)
        at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:237)
        at com.opensymphony.xwork2.interceptor.ConversionErrorInterceptor.intercept(ConversionErrorInterceptor.java:122)
        at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:237)
        at com.opensymphony.xwork2.interceptor.ParametersInterceptor.doIntercept(ParametersInterceptor.java:195)
        at com.opensymphony.xwork2.interceptor.MethodFilterInterceptor.intercept(MethodFilterInterceptor.java:87)
        at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:237)
        at com.opensymphony.xwork2.interceptor.ParametersInterceptor.doIntercept(ParametersInterceptor.java:195)
        at com.opensymphony.xwork2.interceptor.MethodFilterInterceptor.intercept(MethodFilterInterceptor.java:87)
        at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:237)
        at com.opensymphony.xwork2.interceptor.StaticParametersInterceptor.intercept(StaticParametersInterceptor.java:179)
        at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:237)
        at org.apache.struts2.interceptor.MultiselectInterceptor.intercept(MultiselectInterceptor.java:75)
        at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:237)
        at org.apache.struts2.interceptor.CheckboxInterceptor.intercept(CheckboxInterceptor.java:94)
        at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:237)
        at org.apache.struts2.interceptor.FileUploadInterceptor.intercept(FileUploadInterceptor.java:235)
        at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:237)
        at com.opensymphony.xwork2.interceptor.ModelDrivenInterceptor.intercept(ModelDrivenInterceptor.java:89)
        at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:237)
        at com.opensymphony.xwork2.interceptor.ScopedModelDrivenInterceptor.intercept(ScopedModelDrivenInterceptor.java:130)
        at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:237)
        at org.apache.struts2.interceptor.debugging.DebuggingInterceptor.intercept(DebuggingInterceptor.java:267)
        at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:237)
        at com.opensymphony.xwork2.interceptor.ChainingInterceptor.intercept(ChainingInterceptor.java:126)
        at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:237)
        at com.opensymphony.xwork2.interceptor.PrepareInterceptor.doIntercept(PrepareInterceptor.java:138)
        at com.opensymphony.xwork2.interceptor.MethodFilterInterceptor.intercept(MethodFilterInterceptor.java:87)
        at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:237)
        at com.opensymphony.xwork2.interceptor.I18nInterceptor.intercept(I18nInterceptor.java:165)
        at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:237)
        at org.apache.struts2.interceptor.ServletConfigInterceptor.intercept(ServletConfigInterceptor.java:164)
        at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:237)
        at com.opensymphony.xwork2.interceptor.AliasInterceptor.intercept(AliasInterceptor.java:179)
        at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:237)
        at com.opensymphony.xwork2.interceptor.ExceptionMappingInterceptor.intercept(ExceptionMappingInterceptor.java:176)
        at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:237)
        at com.panterra.worldsmart.wsadmin.model.interceptor.ActionMediator.intercept(ActionMediator.java:42)
        at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:237)
        at org.apache.struts2.impl.StrutsActionProxy.execute(StrutsActionProxy.java:52)
        at org.apache.struts2.dispatcher.Dispatcher.serviceAction(Dispatcher.java:488)
        at org.apache.struts2.dispatcher.FilterDispatcher.doFilter(FilterDispatcher.java:395)
        at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:256)
        at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:215)
        at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:279)
        at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:175)
        at org.apache.catalina.core.StandardPipeline.doInvoke(StandardPipeline.java:655)
        at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:595)
        at com.sun.enterprise.web.WebPipeline.invoke(WebPipeline.java:98)
        at com.sun.enterprise.web.PESessionLockingStandardPipeline.invoke(PESessionLockingStandardPipeline.java:91)
        at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:162)
        at org.apache.catalina.connector.CoyoteAdapter.doService(CoyoteAdapter.java:326)
        at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:227)
        at com.sun.enterprise.v3.services.impl.ContainerMapper.service(ContainerMapper.java:170)
        at com.sun.grizzly.http.ProcessorTask.invokeAdapter(ProcessorTask.java:822)
        at com.sun.grizzly.http.ProcessorTask.doProcess(ProcessorTask.java:719)
        at com.sun.grizzly.http.ProcessorTask.process(ProcessorTask.java:1013)
        at com.sun.grizzly.http.DefaultProtocolFilter.execute(DefaultProtocolFilter.java:225)
        at com.sun.grizzly.DefaultProtocolChain.executeProtocolFilter(DefaultProtocolChain.java:137)
        at com.sun.grizzly.DefaultProtocolChain.execute(DefaultProtocolChain.java:104)
        at com.sun.grizzly.DefaultProtocolChain.execute(DefaultProtocolChain.java:90)
        at com.sun.grizzly.http.HttpProtocolChain.execute(HttpProtocolChain.java:79)
        at com.sun.grizzly.ProtocolChainContextTask.doCall(ProtocolChainContextTask.java:54)
        at com.sun.grizzly.SelectionKeyContextTask.call(SelectionKeyContextTask.java:59)
        at com.sun.grizzly.ContextTask.run(ContextTask.java:71)
        at com.sun.grizzly.util.AbstractThreadPool$Worker.doWork(AbstractThreadPool.java:532)
        at com.sun.grizzly.util.AbstractThreadPool$Worker.run(AbstractThreadPool.java:513)
        at java.lang.Thread.run(Thread.java:619)

Please anyone can help me to solve this.

Thanks, B.Sucharitha.

View Answers









Related Tutorials/Questions & Answers:
download file Error in struts2 action class
download file Error in struts2 action class  Hi, i am using bellow block of code for download file : public void downloadGreeting(String... strPrefix = System.getProperty("astsoundsfolderoriginal"); File
Sending error code to access log of tomcat server from Action class
Sending error code to access log of tomcat server from Action class  How to send an error code (500) to access log file when we get null value in an if condition in Action class? Is anyone aware of this! Thanks
Advertisements
how to send my system.out.println in a class file to a jsp in Struts2
how to send my system.out.println in a class file to a jsp in Struts2   System.out.println("File" + f + " contains text " + text + " at line " + hm1.keySet() + " and index "+ hm1.values() ); I want
Sending large data to Action Class error. Struts code - Struts
Sending large data to Action Class error. Struts code  I have a jsp...);} and in action class i want to get the value of variable 'val'.But since this is large string value so it is not passed to action class. So please help me
DTO & Action class - Struts
DTO & Action class  Hi I am really new to struts2. I just wanted to know that if I have a DTO and an action class, how do I put the form data into the DTO? Can someone please explain with a simple example
What is Action Class?
What is Action Class?  What is Action Class? Explain with Example
Understanding Struts Action Class
Class and forward a jsp file through it.  What is Action Class?ADS_TO_REPLACE_1 An Action class in the struts application extends Struts... Understanding Struts Action Class   
Struts Action Class
Struts Action Class  What happens if we do not write execute() in Action class
retrieve in xml file in struts2
retrieve in xml file in struts2  i am using struts2 and trying... properties file using ajax. i now put the values from properties file to map inside the bean class and based on the number entered i retrieve the name. now how
Login Action Class - Struts
Login Action Class  Hi Any one can you please give me example of Struts How Login Action Class Communicate with i-batis
Create Action class
Create Action Class An action is an important portion of web application... an action class you need to extend or import the Action classes or interface... package. The commonly used action class is ActionSupport. An example of action
javascript call action class method instruts
javascript call action class method instruts  in struts2 onchange event call a method in Actionclass with selected value as parameter how can i do
file download
file download  I uploaded a file and saved the path in database. Now i want to download it can u plz provide code
struts2 properties file
struts2 properties file  How to set properties file in struts 2 ?   Struts 2 Format Examples Struts 2 Tutorial
getting db in action class
getting db in action class  hi, Am usin struts in ma application... n i need to interact with the db .. so i used.. getDataSource(request) but it gives me an error.. java.lang.NoSuchMethodError: LoginAction.getDataSource(Ljavax
Is Multiple Actions in Action class - Struts
Is Multiple Actions in Action class  In ActionClass we can use only one action i.e execute(), but in DispatchAction we can use multiple actions.My question is , we can use multiple actions in Action class if(action.equals("add
struts2
struts2  how to read properties file in jsp of struts2   Hi, You can use the Properties class of Java in your action class.ADS.... Thanks   i want the properties file values in jsp not in action
autocall for sturts action class - Struts
in the server on action class should run automatically. how can I do this. help me...autocall for sturts action class  Hi All, We are developing a web application with struts frame work. In this project I have to call an action
class file
class file  How to create class file in jsf easily
File Upload in struts2 - Invalid field value for field
File Upload in struts2 - Invalid field value for field   Hi I am also getting following error while trying to upload a file using struts file tag... struts.xml -> <action name="uploadingFile" class
class file
class file  how to convert java classfile into java sourcefile
file class
file class  Hi Friend, I have a file class it lets me extract all the data from a csv file but I need to align the data properely, seperating... java.util.*; public class ReadCSV{ public ReadCSV (){ } public static
Developing Login Action Class
Developing Login Action Class   ... for login action class and database code for validating the user against database.   Developing Login Action Class  ADS_TO_REPLACE_1
Hibernate error class is not mapped
Hibernate error class is not mapped  Hi, In my application there seems some issue as it is giving error hibernate error class is not mapped. My.... In hibernate.cfg.xml file you should add following entry for your "Users.java" class
Struts2 netbeans 6.5.1 application error - Struts
Struts2 netbeans 6.5.1 application error  i develop struts simple application in netbeans 6.5.1 but every time generate appache error Requested resources not available in so give me solution please any body
validation in struts2 using .xml file
validation in struts2 using .xml file  how to do xml validation in struts2 on dynamic fields   Hello Friend, Please visit the following link:ADS_TO_REPLACE_1 http://www.roseindia.net/struts/struts2/struts2validation
How to create pdf file in struts2.
How to create pdf file in struts2. In this example, you will see the how to create PDF in struts, and how to write message in generated PDF file in struts2...; GeneratePDFAction.java (Action Class) package
file download in struts - Struts
file download in struts  Hello... I've designed an application where i need to download an xml file by creating it... so...i used dom for it.. I... an xml file from database.. Everything's going on well... Now what my problem is i
php download file script
php download file script  PHP script to download file in IE
File Download in jsp
File Download in jsp  file upload code is working can u plz provide me file download
Download PDF file
Download PDF file  How to download PDF file with JSF
Download file - JSP-Servlet
Servlet download file from server  I am looking for a Servlet download file example
class not found error - JDBC
class not found error  thanks for your response. please clarify the following doubts. i am having the specified mysql connector jar file. where that jar file has to be placed. also does the jdbc driver need to be installed
how to download file
how to download file  How do I let people download a file from my page
php download file code
php download file code  PHP code to download the files from the remote server
php download file browser
php download file browser  limiting downloading file system via browser only through my web application
Download a file - Java Beginners
Download a file   Hi, I need a java code to download a file from a website and before downloading it should give me an option to browse and select the location to put the file. Thanks in advance
Forgot Password Action,Struts Forgot Password Action class
roseindia.services.ServiceFinder; public class UserForgetPasswordAction extends Action { public... Forgot Password Action       Forgot Password Action The password forgot Action is invoked
File Download Security
File Download Security   Hello, I trying to create an application in PHP to prevent or provide file download security. So, I need the help of senior... files downloading. Please read this article about File Download Security
csv file download
csv file download  Hello Every one, when user clicks download button I want to retrieve data from mysql database table in csv format using java.if you know please send code. Thanks in Advance   Please visit
Two forms submission to one Action Class in Struts2.0
Two forms submission to one Action Class in Struts2.0  Hi, I have two forms.I want to submit two forms with only one submit button to the same action, same method. How can i get this. Please reply me
about the base class of file
about the base class of file  what is the basic class of file
Error:No Class Found Exception:org.postgresql.driver
Error:No Class Found Exception:org.postgresql.driver  Error:No Class Found Exception:org.postgresql.driver while connecting JDBC With PostgreSQL 8.4 I m running My Program with java 6.0
Java class file
Java class file  How do i open a java class file using eclipse
How to validate a form in action class and forward errors to the jsp in struts?
How to validate a form in action class and forward errors to the jsp in struts?  How to validate a form in action class and forward errors to the jsp in struts
Java file class
Java file class  What is the purpose of the File class
JSP error: class UserForm not found in class model.UserAction
JSP error: class UserForm not found in class model.UserAction  etting the following error in the program..wat shod i do to remove this?I am using... org.apache.struts.actions.IncludeAction; public class UserAction extends DispatchAction { private
struts2
struts2  dear deepak sir plz give the struts 2 examples using applicationresources.properties file
scanner Class Error - Java Beginners
scanner Class Error  Hello Sir ,When i run the program of Scanner Class ,there is Error Can not Resolve Symbol-Scanner how i can solve..., Scanner class is not provided. Check your version.It should work with java 1.5
Struts2
Struts2  Hi, I need a solution for displaying success message in same page in struts2. how to redirect same page in struts2.Please help me.   hi friend, To know how redirect action can be done in struts 2 you can go

Ads