Latest Tutorials| Questions and Answers|Ask Questions?|Site Map



Home Answers Viewqa Struts download file Error in struts2 action class
Login         

View Questions and Answers by Category

Advertisements


 
Have Programming Question? Ask it here!
 
 
 


B.sucharitha
download file Error in struts2 action class
0 Answer(s)      2 years and 8 months ago
Posted in : Struts


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.


Advertisement
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
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
What is Action Class?
What is Action Class?  What is Action Class? Explain with Example
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
Understanding Struts Action Class
Class and forward a jsp file through it.  What is Action Class? An Action... Understanding Struts Action Class   ..." Class. Action class acts as wrapper around the business logic and provides
Struts Action Class
Struts Action Class  What happens if we do not write execute() in Action class
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
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
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
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
struts2
; i want the properties file values in jsp not in action class brother...struts2  how to read properties file in jsp of struts2   Hi, You can use the Properties class of Java in your action class. Properties
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
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
Download file - JSP-Servlet
Servlet download file from server  I am looking for a Servlet download file example
php download file code
php download file code  PHP code to download the files from the remote server
how to download file
how to download file  How do I let people download a file from my page
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
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
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
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
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
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
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
 

 

 

DMCA.com