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



Home Answers Viewqa Java-Beginners IllegalStateException for file opening
Login         

View Questions and Answers by Category

Advertisements


 
Have Programming Question? Ask it here!
 
 
 


B.sucharitha
IllegalStateException for file opening
1 Answer(s)      3 years and 3 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 ) {
        }
    } else {
%>
            <script>
                alert( "This file does not exist." );
                window.history.back();
            </script>
<%
    }
        System.out.println("downloadcallrecoeding jsp end.......................................");
%>





**Error:**
______



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:121)
        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:35 PM


We are providing you the code in jsp.

1)viewFiles.jsp:

<%@ page import="java.io.*"%>
<html>
<table>
<tr><th>File Name</th><th>View File</th></tr>
<%
File f = new File("C:/UploadedFiles");
        File[] files = f.listFiles();
        for(int i=0;i<files.length;i++){
            String name=files[i].getName();
            String path=files[i].getPath();
%>
<tr><td><%=name%></td><td><a href="download.jsp?f=<%=path%>">View</a></td></tr>
     <%
        }
%>
</table>
</html>

2)download.jsp:

<%@page import="java.io.*"%>
<%
String ff=request.getParameter("f");
File f = new File(ff);
    String filename=f.getName();
    response.setContentType("application/zip");
    response.setHeader("Content-Disposition", "attachment;  filename=\""+filename+"\"");

    String name = f.getName().substring(f.getName().lastIndexOf("/") + 1,f.getName().length());
    InputStream in = new FileInputStream(f);
        ServletOutputStream outs = response.getOutputStream();
        int bit = 256;
        int i = 0;
            try{
                    while((bit) >= 0){
                        bit = in.read();
                        outs.write(bit);
                    }
                        } catch (IOException ioe) {
                        ioe.printStackTrace(System.out);
                    }
                    outs.flush();
                    outs.close();
                    in.close(); 
                    %>


Related Tutorials/Questions & Answers:
IllegalStateException for file opening
IllegalStateException for file opening  <%@page import...*"%> <%@include file="sessioncheck.jsp"%> <...){ } File requiredFile = new File(strabsoluteFileName
IllegalStateException for file opening
IllegalStateException for file opening  <%@page import...*"%> <%@include file="sessioncheck.jsp"%> <...){ } File requiredFile = new File(strabsoluteFileName
Advertisements
IllegalStateException
IllegalStateException  whis is the IllegalStateException in java? or define IllegalStateException with exp?   This error occur due... void throwDemonstration( ) { try { throw new IllegalStateException
Error Opening File - Java Interview Questions
. But when I try to export it under Runnbale jar file on my desktop and I run this generated file, a message was displayed: Error opening file. But If I...Error Opening File  Dear, Please if help me to resolve
Exception when opening a excel file in JFrame
Exception when opening a excel file in JFrame  Hello, I have a problem when trying to display a Excel file in a Jframe. The exception is like this: com.jniwrapper.LibraryNotFoundException. here is my code public jexcelTest1
Help with opening a text file upon closing a program.
Help with opening a text file upon closing a program.  I need some... that is a swimming pool volume calculator. It stored that data on a output.txt file but I want that file to open whenever the user exits the program. My code so far
Opening a file in a HTML form
Opening a file in a HTML form In this example, you will first see that a form has been created in HTML format and the code of opening a file has been written... a file in PHP. Opening a File in PHP <?php  $string = $_POST["
Opening Notepad
Opening Notepad  Sir/madam I want to open notepad from java applications and save the contents on it. Can someone please help me to do this. With Regards Vaishnavi Vishwanath   To open the notepad, just go through
Opening files with .jnlp extension on browser!?!?!
Opening files with .jnlp extension on browser!?!?!  I working... file which gets downloaded on client's side on runtime. I searched into the code... where is has been used. I dont want this file to be downloaded into the client's pc
datetime picker is not opening
datetime picker is not opening  Hi I have a java servlet code in this date time picker is not opening. The same opens in JSP code. My code is: **function.js** <script language="javascript" type="text/javascript" src
"opening video data error" in j2me
"opening video data error" in j2me  Any one know about the error c When i am trying to play video on spice device its throw an exception, but the same code work on other devices very well please tell me the issue behind
Opening a URL from an Applet
Opening a URL from an Applet       Introduction This is the example of opening a url in same... used for opening url from an applet. This program is using two functions in which
opening new window - Java Beginners
opening new window  Hi All, I have two classes with me , lets say A and B.when I press a button in class A , the class B should open in a new window.i.e., I want to know, how a new window(B) can be opened by clicking a button
Open The Default Editor to Edit the File
of opening the file in the default editor to edit and save the file. Here... Open The Default Editor to Edit the File   ... the things that helps to open the file in the default editor to edit the file. When
opening new browser with new JSESSIONID using java
opening new browser with new JSESSIONID using java  I am facing following problem, I am trying to open a new browser using java. First i have opened one IE browser and manually. And i ran my LaunchURL.java file, it is opening new
opening node in treeview struts layout - Struts
opening node in treeview struts layout  Example of opening node in treeview struts layoutopening node in treeview struts layout Hello every one, i am new to this group , i am having the same problem , Struts Layout tree view
opening internet browser in java program - Swing AWT
opening internet browser in java program  i want a code to open the internet browser in swing program using JFrame.  Hi Omkar, Use...) { JOptionPane.showMessageDialog(null, "Error in opening browser" + ":\n" + e.getLocalizedMessage
Opening a browser only with body from a java program
Opening a browser only with body from a java program  Hi all, I got following requirement, Opening a browser window only with body and title bar. And based on some condition, after some time, i have to close the browser window
Java - Opening a URL from an Applet
Java - Opening a URL from an Applet       This is the example of opening a url in same... used for opening url from an applet. This program is using two functions
PHP File Handling
PHP File Handling: Every language supports File handling, file handling has... file handling. PHP supports this feature using the following functions: i)    fopen: To open a file in a particular mode, like r: read, w
cannot find java.exe error while opening netbean5.5 - IDE Questions
cannot find java.exe error while opening netbean5.5  HI, 1)i am working netbean5.5 tool.I got the error of cannot find c:\programfiles\java\jdk1.6.0_02. (while opening netbean5.5 shortcut in desktop) . my system jdk path
Opening IE from Java Swing Application in Kiosk mode
Opening IE from Java Swing Application in Kiosk mode  Hi All, I want... window is opening. But I want to open the IE window in Kiosk mode or without address... & Regards, Abhijith   Here is a simple example of opening IE
JAVA SCRIPT CODE FOR OPENING A WEBSITE IN A NEW WINDOW - Java Beginners
JAVA SCRIPT CODE FOR OPENING A WEBSITE IN A NEW WINDOW   PLS TELL ME? HOW CAN I DEFINE A WINDOW.OPEN FUNCTION WITHIN ANOTHER FUNCTION e.g IF THERE ARE THREE FIELDS OF A FORM, AND AFTER CKECKING THAT ALL THE FIELDS HAVING
problem in swing program for opening two windows with same login credentials
problem in swing program for opening two windows with same login credentials  I Face two problems while writing the code in swing program 1.i developed one application using swings that has username,password when i login
Java - Opening a url in new window from an applet
Java - Opening a url in new window from an applet       This is the example of opening a url from an applet. This program shows that how a url is opened in a new document or browser
File
File  How to create .Exe file in jana
file
file  how can copy the information in the file to the string?   Store file data into String
file
file  Could anyone please help me to write a code that does the following: Opens a file named MyName.txt, reads the first line from the file and displays it, and then closes the file. Thank you so much
file
file  Hi,what can delet some of the information of the file
file
file  Hi,how can delet some of the information of the file
file
file  how can add the information to the graphic file
Advertisements
 

 

 

DMCA.com