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



Home Answers Viewqa Java-Beginners problem with response.getOutputStrem()
Login         

View Questions and Answers by Category

Advertisements


 
Have Programming Question? Ask it here!
 
 
 


B.sucharitha
problem with response.getOutputStrem()
1 Answer(s)      3 years and 2 months ago
Posted in : Java Beginners


<%@page import="javax.servlet.*, javax.servlet.http.*,java.io.*,java.util.*,com.kit.log.*,com.kit.db.util.*"%> 
<%@include file="sessioncheck.jsp"%>

<%
System.out.println("downloadcallrecoeding jsp start");
    String strfileName =  request.getParameter("filename");
    String strfilePath =  System.getProperty("callrecordingfilespath");
    String strabsoluteFileName = strfilePath + strfileName + ".mp3";

    String strtempfileName =  request.getParameter("filename") + ".mp3";
    try{
        strtempfileName =  strtempfileName.substring(6, strtempfileName.length());
    }catch(Exception e){
    }
    File requiredFile = new File(strabsoluteFileName);
    if ( requiredFile.exists()) {
        response.setHeader("Content-Type", "audio/mpeg; filename=" + strabsoluteFileName);
        response.setHeader("Content-Disposition", "attachment; filename=" + strtempfileName);
        response.setHeader("Content-Length", "" + requiredFile.length());
        try {
                    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 e ) {
        }}


Error is:


Servlet.service() for servlet jsp threw exception
java.lang.IllegalStateException: getOutputStream() has already been called for this response
        at org.apache.catalina.connector.Response.getWriter(Response.java:599)
        at org.apache.catalina.connector.ResponseFacade.getWriter(ResponseFacade.java:195)
        at org.apache.jasper.runtime.JspWriterImpl.initOut(JspWriterImpl.java:124)
        at org.apache.jasper.runtime.JspWriterImpl.flushBuffer(JspWriterImpl.java:117)
        at org.apache.jasper.runtime.PageContextImpl.release(PageContextImpl.java:191)
        at org.apache.jasper.runtime.JspFactoryImpl.internalReleasePageContext(JspFactoryImpl.java:115)
        at org.apache.jasper.runtime.JspFactoryImpl.releasePageContext(JspFactoryImpl.java:75)
        at org.apache.jsp.AdminSaaS.downloadcallrecording_jsp._jspService(downloadcallrecording_jsp.java:122)
        at org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:97)
        at javax.servlet.http.HttpServlet.service(HttpServlet.java:802)
        at org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:332)
        at org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:314)
        at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:264)
        at javax.servlet.http.HttpServlet.service(HttpServlet.java:802)
        at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:252)
        at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:173)
        at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:213)
        at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:178)
        at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:126)
        at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:105)
        at org.apache.catalina.valves.FastCommonAccessLogValve.invoke(FastCommonAccessLogValve.java:495)
        at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:107)
        at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:148)
        at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:869)
        at org.apache.coyote.http11.Http11BaseProtocol$Http11ConnectionHandler.processConnection(Http11BaseProtocol.java:664)
        at org.apache.tomcat.util.net.PoolTcpEndpoint.processSocket(PoolTcpEndpoint.java:527)
        at org.apache.tomcat.util.net.LeaderFollowerWorkerThread.runIt(LeaderFollowerWorkerThread.java:80)
        at org.apache.tomcat.util.threads.ThreadPool$ControlRunnable.run(ThreadPool.java:684)
        at java.lang.Thread.run(Thread.java:595)

Advertisement
View Answers

August 25, 2011 at 5:46 PM


You haven't used import statement properly. Do the following:

<%@page import="javax.servlet.*, javax.servlet.http.*,java.io.*,java.util.*,com.kit.log.*,com.kit.db.util.*"%>


Related Tutorials/Questions & Answers:
Advertisements
 

 

 

DMCA.com