Preventing servlet output stream to flush

I increased the buffersize in the response object in order to make it possible for the entire jsp page to process before writing any output to the webclient.
BUT since I use dynamic jsp-includes I fail to accomplish this, since according to the JSP1.3 specification the output stream is flushed before processing a dynamic include instruction.
Is there a way I can make JSP to process the include and write output to buffer WITHOUT flushing it?
Regards, Jon

No I am using JSP 1.3. And I want to do the following:<%
for (int i = 0; i < 5; i++) {
   // include("file_"+ i +".jsp");
%>This to include file_0.jsp up to file_4.jsp.
I assume the <jsp:include>tag is preprocessed hence only included once.

Similar Messages

  • Read Servlet output stream

    how can i read servlet output stream

    i m using SAX to create an XML.
    I set result to "Servlet Output Stream" as shown below :->
    SAXTransformerFactory saxTF = SAXTransformerFactory.newInstance();
    TransformerHandler th = saxTF.newTransformerHandler();
    Transformer t = th.getTransformer();
    StreamResult stRes = new StreamResult(res.getOutputStream());
    th.setResult(stRes);
    th.startDocument();
    what i want to wright the same xml result in file at the same time(parallel y).

  • Servlet Output Streams and clearing

    I am using servlets, and I want to be able to print something repeatedly. Well, that's not exactly true: I can print something repeatedly. Using a ServletOutputStream, it doesn't seem possible to clear what has already been written. Here's the code:
    import javax.servlet.*;
    import javax.servlet.http.*;
    import java.util.*;
    import java.io.*;
    public class AlwaysTime extends HttpServlet {
         public void doPost(HttpServletRequest req, HttpServletResponse res)                throws ServletException, IOException {
              HttpServletResponse oldRes = res;
              Date now = new Date();
              res.setContentType("text/html");
              ServletOutputStream out = res.getOutputStream();
              out.println("<html>");
              out.println("<head>");
              out.println("<title>Clock</title>");
              out.println("</head>");
              out.println("<body>");
              out.println("<h1 align=\"Center\">");
              out.println(now.toString());
              out.println("</h1>");
              out.println("</body>");
              out.println("</html>");
              try {
                 Thread.sleep(1000);
              } catch (InterruptedException ie) {}
              // Do nothing: wait for 1 second.
              doPost(req, oldRes);
         public void doGet(HttpServletRequest req, HttpServletResponse res)
              throws ServletException, IOException {
              doPost(req, res);
    }This code prints the time every second, but I want to clear the previous output stream. I thought the code shown above would work, but of course, oldRes points to the same object as res. But I don't know how to clear an output stream, so that it is completely empty. Instead, each of the new lines are appended to the same output stream.
    This doesn't only apply to servlet output streams: is there some way to clear the System output stream, for instance?
    But mainly the servlet output stream ...

    You would not want to use HTTP for this type of functionality. HTTP is known as a 'stateless' protocol that simply returns one exact response for each request. So, there is not way to 'clear' the stream (technically, you would not do so for 'normal' streams either, but when you add HTTP into the mix, the task is definitely not possible).
    You could implement the above using a RSS feed, or by using HTTP meta-refresh tags on the page itself ot resubmit the requests every second (though this would be inefficient). An applet would also do the task.
    - Saish

  • REG:SERVLET OUTPUT STREAM

    I am trying to implement upload/view functionality..To view an uploaded txt file or html file,I am just flushing out the file contents into servlet's output stream..The content type has been set appropriately.
    The problem is for some html files ia m able to see the file contents in the browser,and for some html files,the browser displays a open/save dialog box..
    Can any1 explain me why this discrepency?Its the sam e code and same content type..why is it so?

    Thanks for ur reply...
    All i mentioned was in the same browser..PFB the code snippet
         ServletOutputStream pic = null;
         pic = response.getOutputStream();
         ByteArrayOutputStream baos = new ByteArrayOutputStream();
         byte b[] = new byte[5*1024];
         while(true)
              int bytes = in.read(b);
              if(bytes == -1)
                   break;
              baos.write(b, 0, bytes);
         response.setContentLength(b.length);
         b = baos.toByteArray();
         pic.write(b, 0, b.length);
         pic.flush();
         pic.close()

  • Writing to servlet output stream

    Hi All,
    I am writing to a servlet(imageservlet) output stream in a jsp page two times as follows:
    <img src="\imageservlet?key=x1">
    <img src="\imageservlet?key=x2">
    It is causing memory errors. Do I have to take special precautions?
    Thanks inadvance.

    Hi,
    THis is my servlet code.
    import java.io.*;
    import java.io.StringWriter;
    import javax.servlet.http.*;
    import javax.servlet.*;
    import java.awt.Color;
    import com.trizetto.healthweb.service.GenerateImage;
    * Simple servlet to use with Image I/O generator
    public class GenerateImageServlet extends HttpServlet
    public void doGet(HttpServletRequest request, HttpServletResponse response)
    throws IOException, ServletException
         String className="PieChartGenerator";
         if(request.getParameter("keyName").equals("Pie"))
              className=PieChartGenerator";
         else if( request.getParameter("keyName").equals("Gantt") )
              className="GanttChartGenerator";
    try
    GenerateImage ge=
    (GenerateImage) Class.forName(className).newInstance();
    String type = ge.createImage(response.getOutputStream());
    response.setContentType(type);
    catch (Exception e)
    throw new ServletException(e);
    But this one does not generate image. The image is generated from the Graphics object of the Frame.
    Something like the following code:
    http://www.javaworld.com/javaworld/jw-05-2000/servlets/Servlets.zip
    http://www.javaworld.com/javaworld/jw-05-2000/jw-0505-servlets-p2.html
    http://www.javaworld.com/javaworld/jw-05-2000/jw-0505-servlets-p1.html
    I am using Java 1.1.
    I am running my app. in websphere. The error happens randomly while I am stopping the websphere application server.
    Thanks in advance.

  • Servlet output streaming problem

    Hi all !
              Given the following JSP/Servlet:
              <html>
              <body>
              Test
              <%
              out.println( "<h1>Countdown</h1>" );
              for ( int i = 10; i > 0; i-- ) {
              out.print( "<h1>" );
              out.print( i );
              out.println( "</h1>" );
              out.flush();
              try {
              // simulate access to an external system
              Thread.sleep( 1000 );
              catch ( InterruptedException e ) {}
              out.println( "<h1>Liftoff</h1>" );
              out.close();
              %>
              </body>
              </html>
              This prints out the numbers 10 to 0 with a seconds pause inbetween.
              This works on our development server. However, after uploading to the
              production server, the page is blank for ten seconds and then shows
              all the numbers in one chunk. The problem is that the out.flush()
              statement appearently is ignored by the weblogic server. No errors or
              exceptions in any logs.
              Is this a configuration issue ?
              Setup:
              * Weblogic 5.1
              * Linux Redhat 7.2
              Thanks.
              Pål O.
              

    Do you have a proxy in front of WL? Do you have a web proxy on the client
              side?
              Peace,
              Cameron Purdy
              Tangosol, Inc.
              http://www.tangosol.com/coherence.jsp
              Tangosol Coherence: Clustered Replicated Cache for Weblogic
              "Pål O. Kristiansen" <[email protected]> wrote in message
              news:[email protected]...
              > Hi all !
              >
              > Given the following JSP/Servlet:
              >
              > <html>
              > <body>
              > Test
              > <%
              > out.println( "<h1>Countdown</h1>" );
              > for ( int i = 10; i > 0; i-- ) {
              > out.print( "<h1>" );
              > out.print( i );
              > out.println( "</h1>" );
              > out.flush();
              > try {
              > // simulate access to an external system
              > Thread.sleep( 1000 );
              > }
              > catch ( InterruptedException e ) {}
              > }
              > out.println( "<h1>Liftoff</h1>" );
              > out.close();
              > %>
              > </body>
              > </html>
              >
              > This prints out the numbers 10 to 0 with a seconds pause inbetween.
              > This works on our development server. However, after uploading to the
              > production server, the page is blank for ten seconds and then shows
              > all the numbers in one chunk. The problem is that the out.flush()
              > statement appearently is ignored by the weblogic server. No errors or
              > exceptions in any logs.
              >
              > Is this a configuration issue ?
              >
              > Setup:
              > * Weblogic 5.1
              > * Linux Redhat 7.2
              >
              > Thanks.
              >
              > Pål O.
              

  • How can I put an output stream (HTML) from a remote process on my JSF page

    Hello,
    I've a question if someone could help.
    I have a jsf application that need to execute some remote stuff on a different process (it is a SAS application). This remote process produces in output an html table that I want to display in my jsf page.
    So I use a socket SAS class for setting up a server socket in a separate thread. The primary use of this class is to setup a socket listener, submit a command to a remote process (such as SAS) to generate a data stream (such as HTML or graphics) back to the listening socket, and then write the contents of the stream back to the servlet stream.
    Now the problem is that I loose my jsf page at all. I need a suggestion if some one would help, to understand how can I use this html datastream without writing on my Servlet output stream.
    Thank you in advance
    A.
    Just if you want to look at the details .....
    // Create the remote model
    com.sas.sasserver.submit.SubmitInterface si =
    (com.sas.sasserver.submit.SubmitInterface)
    rocf.newInstance(com.sas.sasserver.submit.SubmitInterface.class, connection);
    // Create a work dataset
    String stmt = "data work.foo;input field1 $ field2 $;cards;\na b\nc d\n;run;";
    si.setProgramText(stmt);
    // Setup our socket listener and get the port that it is bound to
    com.sas.servlet.util.SocketListener socket =
    new com.sas.servlet.util.SocketListener();
    int port = socket.setup();
    socket.start();
    // Get the localhost name
    String localhost = (java.net.InetAddress.getLocalHost()).getHostAddress();
    stmt = "filename sock SOCKET '" + localhost + ":" + port + "';";
    si.setProgramText(stmt);
    // Setup the ods options
    stmt = "ods html body=sock style=brick;";
    si.setProgramText(stmt);
    // Print the dataset
    stmt = "proc print data=work.foo;run;";
    si.setProgramText(stmt);
    // Close
    stmt = "ods html close;run;";
    si.setProgramText(stmt);
    // get my output stream
    context = FacesContext.getCurrentInstance();
    HttpServletResponse response = (HttpServletResponse) context.getExternalContext().getResponse();
    ServletOutputStream out = response.getOutputStream();
    // Write the data from the socket to the response
    socket.write(out);
    // Close the socket listener
    socket.close();

    The system exec function is on the Communication palette. Its for executing system commands. On my Win2K system, the help for FTP is:
    "Ftp
    Transfers files to and from a computer running an FTP server service (sometimes called a daemon). Ftp can be used interactively. Click ftp commands in the Related Topics list for a description of available ftp subcommands. This command is available only if the TCP/IP protocol has been installed. Ftp is a service, that, once started, creates a sub-environment in which you can use ftp commands, and from which you can return to the Windows 2000 command prompt by typing the quit subcommand. When the ftp sub-environment is running, it is indicated by the ftp command prompt.
    ftp [-v] [-n] [-i] [-d] [-g]
    [-s:filename] [-a] [-w:windowsize] [computer]
    Parameters
    -v
    Suppresses display of remote server responses.
    -n
    Suppresses autologin upon initial connection.
    -i
    Turns off interactive prompting during multiple file transfers.
    -d
    Enables debugging, displaying all ftp commands passed between the client and server.
    -g
    Disables file name globbing, which permits the use of wildcard characters (* and ?) in local file and path names. (See the glob command in the online Command Reference.)
    -s:filename
    Specifies a text file containing ftp commands; the commands automatically run after ftp starts. No spaces are allowed in this parameter. Use this switch instead of redirection (>).
    -a
    Use any local interface when binding data connection.
    -w:windowsize
    Overrides the default transfer buffer size of 4096.
    computer
    Specifies the computer name or IP address of the remote computer to connect to. The computer, if specified, must be the last paramete
    r on the line."
    I use tftp all of the time to transfer files in a similar manner. Test the transfer from the Windows command line and copy it into a VI. Pass the command line to system exec and wait until it's done.

  • Servlet output not displayed properly in Internet Explorer

    Hi All,
    I'm developing a servlet which uploads a file. After the servlet parses the request body, it stores the file contents as a binary string in the database. While displaying the contents of the attached file, the IE(Internet Explorer) is ignoring all the newlines and spaces. IThe same uploaded file when viewed through Firefox browser is being displayed properly. I've added some debug statements to print the filecontent before sending it to servlet output stream. They look exactly as they were in the uploaded file. The MIME type is application/octet-stream.
    I've also made the response to accept "ISO-8859-1" and "UTF-8" charsets, yet the IE is not rendering the file contents properly. The code looks like this,
    response.setContentType("text/html; charset= ISO-8859-1, UTF-8");
    byte[] buff = attachment.getAttachObject();
    OutputStream out = response.getOutputStream();
    out.write(buff);
    out.close();
    I've tried using PrintWriter also. I've tried changing the content types, character encodings of request and response objects, still couldn't resolve the issue. What really baffles me is that when it's displaying properly in Firefox, why can't it render properly in IE? I'm using Win XP SP2, and IE version is 6.0.29. The content which is being sent to the output stream contains newline and space characters, but they are not displayed in the browser. Did any one face this sort of issue? Your help is highly appreciated.
    Thanks,
    Tarun.

    Hi,
    Thanks for looking into the issue. Let me tell you that I've tried keeping various content-types like text/plain, text/xml etc, but in none of those cases the IE rendered the output properly. But with the same content-type i.e text/html or text/plain, Firefox is able to render the file content properly. I've tried a brutal force approach like below,
    response.setContentType("text/plain");
    PrintWriter out = response.getWriter();
    String str = new String(attachment.getAttachObject());
    char[] buff = str.toCharArray();
    for(i=0;i< buff.length; i++)
    int n = (int)buff;
    if(n == 10)
    out.println();
    else
    out.print(buff[i]);
    out.close();
    I was trying to print a newline whenever I find a newline character in the file content. Even this didn't work. Please suggest me some way to get rid of this problem.

  • Error flushing output stream when stop button is used

    Hello,
    I have a servlet running on the Sun ONE Web server 6.1 that throws this error message: "java.io.IOException: WEB8004: Error flushing the output stream".
    Through my testing, it seems as if this is caused by the user pressing the stop button before the output can be completely commited to the client. Strangely enough the error seems to thrown when IE is the browser but not when Firefox is. My guess is that what is happening is the client connection is closed when stop is pressed in IE and the server cannot write to the client anymore so the error is thrown.
    I was wondering if anyone has any insight into how to prevent this from getting thrown. I realize that this error is not a major thing and probably doesn't need to be worried about, but it is quite annoying because webmaster gets emailed anytime an exception is thrown so cutting down on pointless exceptions is something we like to do :)
    Thanks in advance.

    Hay, did you ever figure it out. I am getting it when one user hits my Servlet to download a specific piece of data????? I can't figure it out?
    Thanks for the info,
    Jeff

  • Error flushing the output stream in Sun One server

    Hi All,
    I was running my servlet code in iPlanet 6.0 version and it was working fine. I upgraded my web server to new Sun One server (Oracle-iPlanet-Web-Server-7.0.9). With the new web server almost 90% of my application works fine, but there is a features in my application to download an Excel sheet by clicking a button. This feature is failing in new Sun One web server.
    Below are my piece of code and the error log I m getting. Can anyone tell me how I can fix this error, I mean is there any web server specific change or configuration parameter need to be set.
    Please ask for any information regarding my server configuration settings if needed for finding a solution for this
    Code:
    byte abyte0[] = new byte[1024];
    BufferedInputStream bufferedinputstream=null;
    BufferedOutputStream bufferedoutputstream=null;
    java.io.InputStream inputstream = httpurlconnection.getInputStream();
    bufferedinputstream = new BufferedInputStream(inputstream);
    bufferedoutputstream = new BufferedOutputStream(httpservletresponse.getOutputStream());
    int j;
    long byteCount=0;
    while((j = bufferedinputstream.read(abyte0, 0, 1024)) != -1)
    byteCount=byteCount+j;
    if(logger != null && logger.traceOn())
    logger.log("total"+byteCount);
    logger.log("Read bytes:"+j);
    bufferedoutputstream.write(abyte0, 0, j);
    if(logger != null && logger.traceOn())
    logger.log("Wrote bytes:"+j);
    bufferedoutputstream.flush(); // <<<<<< ERROR POINT >>>>>>
    Error Log :
    ClientAbortException: java.io.IOException: WEB8004: Error flushing the output stream
    at org.apache.coyote.tomcat5.OutputBuffer.doFlush(OutputBuffer.java:343)
    at org.apache.coyote.tomcat5.OutputBuffer.flush(OutputBuffer.java:313)
    at org.apache.coyote.tomcat5.CoyoteOutputStream.flush(CoyoteOutputStream.java:147)
    at java.io.BufferedOutputStream.flush(BufferedOutputStream.java:124)
    at com.reuters.bdec.as.ASRequestHandler.processResponse(ASRequestHandler.java:285)
    at com.reuters.bdec.as.ASRequestHandler.initiateGetRequest(ASRequestHandler.java:89)
    at com.reuters.bdec.as.ASRequestHandler.proceedToDestination(ASRequestHandler.java:220)
    at com.reuters.bdec.as.ASExtension.authorisationCheck(ASExtension.java:84)
    at com.reuters.bdec.as.ASExtension.doGet(ASExtension.java:114)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:794)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:915)
    at org.apache.catalina.core.ApplicationFilterChain.servletService(ApplicationFilterChain.java:398)
    at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:277)
    at org.apache.catalina.core.StandardContextValve.invokeInternal(StandardContextValve.java:255)
    at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:188)
    at org.apache.catalina.core.StandardPipeline.doInvoke(StandardPipeline.java:586)
    at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:556)
    at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:187)
    at org.apache.catalina.core.StandardPipeline.doInvoke(StandardPipeline.java:586)
    at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:556)
    at com.sun.webserver.connector.nsapi.NSAPIProcessor.service(NSAPIProcessor.java:160)
    Caused by: java.io.IOException: WEB8004: Error flushing the output stream
    at com.sun.webserver.connector.nsapi.NSAPIProcessor.action(NSAPIProcessor.java:243)
    at org.apache.coyote.Response.action(Response.java:197)
    at org.apache.coyote.tomcat5.OutputBuffer.doFlush(OutputBuffer.java:339)
    ... 20 more

    Don't flush it yourself. The servlet container will automatically flush for you once its send buffer is full. You can change the size of the send buffer though.

  • Flushing output streams

    Hello,
              I was a getting a harmlous excpetion :
              <4/06/2002 16:48:04> <Error> <HTTP> <Servlet execution in servlet
              context "WebAppServletContext(5985988,root,/root)" failed,
              java.net.ProtocolException: Didn't meet stated Content-Length, wrote:
              '7358
              4' bytes instead of stated: '94440' bytes.
              java.net.ProtocolException: Didn't meet stated Content-Length, wrote:
              '73584' bytes instead of stated: '94440' bytes.
              at
              weblogic.servlet.internal.ServletOutputStreamImpl.finish(ServletOutputStreamImpl.java:413)
              at
              weblogic.servlet.internal.ServletResponseImpl.send(ServletResponseImpl.java:974)
              at
              weblogic.servlet.internal.ServletRequestImpl.execute(ServletRequestImpl.java:1964)
              at weblogic.kernel.ExecuteThread.execute(ExecuteThread.java:137)
              at weblogic.kernel.ExecuteThread.run(ExecuteThread.java:120)
              I read about it on this newsgroup, and I saw some people suggesting to
              flush the output streams with ( out.flush()).
              But this is weird, doesn't Weblogic flush the output streams by itself??
              I had the same application running on tomcat before and everything was
              fine, I didn't have to flush the output streams with tomcat
              And what is the consequence of not flushing the output streams.
              Thanks guys
              Itani
              [att1.html]
              

    I have the same problem. I have seen a lot of messages reporting this
              problem... what is the right solution? Can weblogic become instable
              due to this condition?
              I use some Oreilly classes (com.oreilly.servlet.MultipartRequest) to
              intercept some POST data; Is there anyone who knows if these classes
              can cause the ProtocolException problem?
              Bye
              Luca
              "Vinod Mehra" <[email protected]> wrote in message news:<[email protected]>...
              > No flush will not help here.
              >
              > This exception will show up in only two cases:
              >
              > 1. You wrote less than the promised content length was.
              >
              > 2. While you were writing the client terminated the connection. I
              > remember we used
              > to throw this ProtocolException exception at the end, which was
              > unnecessary.
              > I know this problem has been fixed. We don't throw this exception
              > anymore
              > when the client abnormally terminates the connection. I believe the
              > problem has
              > been fixed in 610sp2. Which release/service pack are you using? If
              > you
              > can't upgrade and need a one off patch please contact support.
              > CR057091
              > was used to track this problem. One off patches are available for
              > 610sp1 and
              > 510sp12.
              >
              > Cheers!
              > --Vinod.
              > "Mohamed Itani" <[email protected]> wrote in message
              > news:[email protected]...
              > Hello,
              > I was a getting a harmlous excpetion :
              >
              > <4/06/2002 16:48:04> <Error> <HTTP> <Servlet execution in servlet
              > context "WebAppServletContext(5985988,root,/root)" failed,
              > java.net.ProtocolException: Didn't meet stated Content-Length, wrote:
              > '7358
              > 4' bytes instead of stated: '94440' bytes.
              > java.net.ProtocolException: Didn't meet stated Content-Length, wrote:
              > '73584' bytes instead of stated: '94440' bytes.
              > at
              > weblogic.servlet.internal.ServletOutputStreamImpl.finish(ServletOutputStr
              > eamImpl.java:413)
              > at
              > weblogic.servlet.internal.ServletResponseImpl.send(ServletResponseImpl.ja
              > va:974)
              > at
              > weblogic.servlet.internal.ServletRequestImpl.execute(ServletRequestImpl.j
              > ava:1964)
              > at
              > weblogic.kernel.ExecuteThread.execute(ExecuteThread.java:137)
              > at weblogic.kernel.ExecuteThread.run(ExecuteThread.java:120)
              >
              > I read about it on this newsgroup, and I saw some people suggesting to
              > flush the output streams with ( out.flush()).
              >
              > But this is weird, doesn't Weblogic flush the output streams by
              > itself??
              > I had the same application running on tomcat before and everything was
              > fine, I didn't have to flush the output streams with tomcat
              >
              > And what is the consequence of not flushing the output streams.
              >
              > Thanks guys
              > Itani
              >
              >
              >
              > --
              

  • Not able to flush the data output stream in n/w prg.

    Hi,
    I am trying to send and receive the data using TCP/IP channel using socket programming.
    Following is the server side code I have
    Socket socket = server_socket.accept();
    OutputStream output = socket.getOutputStream();
    BufferedReader input = new BufferedReader(new InputStreamReader(socket.getInputStream()));
    String inputMessage = (String) input.readLine();
    System.out.println(inputMessage);
    output.write("Message from server");
    output.flush();I am able to receive the message from the client and as per the code the message is getting printed in the console. But I am unable to send the message back to the Client inspite of flushing the output stream.
    I am sure that the problem is because of the flush method which is not acutally flushing the data. If I use the "println" method instead of the write & flush method, everything seems to be working fine. I do not want to use the "println" method because I get an extra new line character in the msg I send to the Client.
    Any help on this is appreciated!

    No. I am not using BufferedReader to listen for the server response. Given below is my client side code.
    Socket socket = new Socket(<ip>, <port>);
    InputStream input = socket.getInputStream();
    PrintWriter output = new PrintWriter(socket.getOutputStream(),true);
    output.println("Request from the client");
    System.out.println("Waiting for the server response...");
    byte buffer[] = new byte[2000];
    input.read(buffer);
    System.out.println(new String(byte));I am not receiving the message from server, it hangs on "Waiting for the server response..".

  • Is there a way to flush out a socket's output stream without...

    ...having to close it (the stream)?
    I'm trying to implement a keep-alive feature in a simple HTTP Server application. This is a draft of the code I have trouble with:
    ==========
    //'clientSocket' is the socket obtained by the 'serverSocket.accept()' method
    OutputStream out = clientSocket.getOutputStream();
    //'message' is a string to be sent to the client
    InputStream data = new ByteArrayInputStream(message.getBytes());
    byte[] buff = new byte[2048];
    while (true)
    int read = data.read(buff, 0, 2048);
    if (read <= 0)
    break;
    out.write(buff, 0, read);
    out.flush();
    ==========
    If I don't call 'out.close()', the data will not be sent to the client.
    If I call 'out.close()', the data will be sent, but the socket will be closed too, which I don't want to. I need to be able to reuse that socket .
    Is there any way to properly push out the data to the client without having to close the output stream?

    ...having to close it (the stream)?Yes. OutputStream.flush(). But if you're not using any kind of buffered writer/output stream you don't even have to do that.
    If I don't call 'out.close()', the data will not be sent to the client.Untrue. The client will read everything that has been written If you don't close the output stream, the client will never get the EOS indication (e.g. read() returning -1). So if your client is looping until that happens it will loop forever ...
    Your problem at the moment is at the reading end.

  • Exception writing binary data to the output stream to client -Broken pipe

    Hi,
    I am trying to use the drag & drop feature using Contributor mode of Webcenter sites. Single Image Page Attribute is working properly where as Multiple Image Page Attribute throws the following error:
    [ERROR] [.kernel.Default (self-tuning)'] [logging.cs.satellite.request] Exception writing binary data to the output stream to client 10.191.117.106
    java.net.SocketException: Broken pipe
         at java.net.SocketOutputStream.socketWrite0(Native Method)
         at java.net.SocketOutputStream.socketWrite(SocketOutputStream.java:92)
         at java.net.SocketOutputStream.write(SocketOutputStream.java:136)
         at weblogic.servlet.internal.ChunkOutput.writeChunkTransfer(ChunkOutput.java:568)
         at weblogic.servlet.internal.ChunkOutput.writeChunks(ChunkOutput.java:539)
         at weblogic.servlet.internal.ChunkOutput.flush(ChunkOutput.java:427)
         at weblogic.servlet.internal.ChunkOutput$2.checkForFlush(ChunkOutput.java:648)
         at weblogic.servlet.internal.ChunkOutput.write(ChunkOutput.java:333)
         at weblogic.servlet.internal.ChunkOutputWrapper.write(ChunkOutputWrapper.java:148)
         at weblogic.servlet.internal.ServletOutputStreamImpl.write(ServletOutputStreamImpl.java:148)
         at COM.FutureTense.Servlet.ServletRequest$OutputOutputStream.write(ServletRequest.java:80)
         at COM.FutureTense.Servlet.ServletRequest.write(ServletRequest.java:1633)
         at com.openmarket.Satellite.RequestContext.write(RequestContext.java:1123)
         at com.openmarket.Satellite.BytePiece.stream(DataPiece.java:253)
         at com.openmarket.Satellite.CacheObjectImpl.stream(CacheObjectImpl.java:651)
         at com.openmarket.Satellite.Http11Responder.respondForWrapper(Http11Responder.java:142)
         at com.openmarket.Satellite.WrapperAwareResponder.respond(WrapperAwareResponder.java:36)
         at com.openmarket.Satellite.SatelliteServer.execute(SatelliteServer.java:85)
         at com.openmarket.Satellite.servlet.BaseServlet.doGet(BaseServlet.java:118)
         at javax.servlet.http.HttpServlet.service(HttpServlet.java:707)
         at javax.servlet.http.HttpServlet.service(HttpServlet.java:820)
         at weblogic.servlet.internal.StubSecurityHelper$ServletServiceAction.run(StubSecurityHelper.java:227)
         at weblogic.servlet.internal.StubSecurityHelper.invokeServlet(StubSecurityHelper.java:125)
         at weblogic.servlet.internal.ServletStubImpl.execute(ServletStubImpl.java:301)
         at weblogic.servlet.internal.TailFilter.doFilter(TailFilter.java:26)
         at weblogic.servlet.internal.FilterChainImpl.doFilter(FilterChainImpl.java:56)
         at com.fatwire.wem.sso.cas.filter.CASFilter.doFilter(CASFilter.java:557)
         at com.fatwire.wem.sso.SSOFilter.doFilter(SSOFilter.java:51)
         at weblogic.servlet.internal.FilterChainImpl.doFilter(FilterChainImpl.java:56)
         at weblogic.servlet.internal.WebAppServletContext$ServletInvocationAction.wrapRun(WebAppServletContext.java:3730)
         at weblogic.servlet.internal.WebAppServletContext$ServletInvocationAction.run(WebAppServletContext.java:3696)
         at weblogic.security.acl.internal.AuthenticatedSubject.doAs(AuthenticatedSubject.java:321)
         at weblogic.security.service.SecurityManager.runAs(SecurityManager.java:120)
         at weblogic.servlet.internal.WebAppServletContext.securedExecute(WebAppServletContext.java:2273)
         at weblogic.servlet.internal.WebAppServletContext.execute(WebAppServletContext.java:2179)
         at weblogic.servlet.internal.ServletRequestImpl.run(ServletRequestImpl.java:1490)
         at weblogic.work.ExecuteThread.execute(ExecuteThread.java:256)
         at weblogic.work.ExecuteThread.run(ExecuteThread.java:221)
    Thanks
    KarthiK

    Thank u very much,
         FileOutputStream opGif = new FileOutputStream(destFile, false);
    I have changed above line with the following line:
         PrintWriter opGif = new PrintWriter ( new FileWriter(destFile, false));
    and now this code is working very fine.
    Thanks once again...

  • Store Output Stream into String

    Hello
    I want to store my out put stream in to string so that i can use it latter.
    out.println("Nilesh patel");
    out.println("[email protected]");
    out.println("Ahmedabad");
    it is "Nilesh patel [email protected] Ahmedabad" but i want to store into string like
    String tmp = out.toString();
    it is return the hash code of out object how can i store this value in String variable?

    To me, the most elegant way to do this would be with a Servlet Filter.
    You use a ResponseWrapper to create a "BufferedResponse" object, and pass that down to the next JSP/Servlet. Basically you have to override methods such as getWriter(), getOutputStream()...
    The JSP/servlet works as normal, but any calls to out.println() can be under your control.
    This simple class might help:
    public class RedirectingServletResponse extends HttpServletResponseWrapper {
        RedirectServletStream out;
         * @param arg0
        public RedirectingServletResponse(HttpServletResponse response, OutputStream out) {
            super(response);
            this.out = new RedirectServletStream(out);
        /* (non-Javadoc)
         * @see javax.servlet.ServletResponse#flushBuffer()
        public void flushBuffer() throws IOException {
            out.flush();
        /* (non-Javadoc)
         * @see javax.servlet.ServletResponse#getOutputStream()
        public ServletOutputStream getOutputStream() throws IOException {
            return out;
        /* (non-Javadoc)
         * @see javax.servlet.ServletResponse#getWriter()
        public PrintWriter getWriter() throws IOException {
            return new PrintWriter(out);
        private static class RedirectServletStream extends ServletOutputStream {
            OutputStream out;
            RedirectServletStream(OutputStream out) {
                this.out = out;
            public void write(int param) throws java.io.IOException {
                out.write(param);
    }You then use it something like this:
    public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) {
      // create an output stream - to file, to memory...
      ByteArrayOutputStream out = new ByteArrayOutputStream();
      // create the "dummy" response object
      RedirectingServletResponse dummyResponse = new RedirectingServletResponse(response, out);
      // pass it on to the next level:
      chain.doFilter(request, dummyResponse);
      // at this point the OutputStream has had the response written into it.
      byte[] result = out.getByteArray();
      // now you can do with it what you will.
    }There is probably a better way - providing response that will write any output to two output streams - the original and an alternative one (file) would be a good option.
    Hope this helps,
    evnafets

Maybe you are looking for

  • Payment Document Number in F110

    Hi All, When I want to use F110 for automatic payment, I have select one vendor with the same currency, payment method, payment terms, house bank. But when I run the proposal, I see there is a list and it is grouping by differeny payment document num

  • I went through all of the steps to renew my account and still cannot use my cloud.

    When in the name of Geldar's ghost can I use the creative cloud programs again???

  • Hold Button Not Working

    The hold button on my iPod video recently stopped working for no reason I can see (I've never dropped my iPod or gotten it wet or anything). Essencially, when I switch the hold button on, nothing happens (it certainly does not lock the buttons and th

  • Returns option for credit memo

    Hi,                      In 2007 version in A/R,when we are creating crdit memo we have the option of copy from Returns.But evenafter creating the Returns we can't get any returns document in the copy from list.Can somebody explain why that option is

  • Creating a iPhoto Book

    I went brain dead and forgot how to delete a page from my iPhoto book that I am creating. The instructions are not obvious to me. Thank you. Light4c