com.oreilly.servlet
类 MultipartResponse

java.lang.Object
  继承者 com.oreilly.servlet.MultipartResponse

public class MultipartResponse
extends Object

A utility class to generate multipart/x-mixed-replace responses, the kind of responses that implement server push. Note that Microsoft Internet Explorer does not understand this sort of response.

To use this class, first construct a new MultipartResponse passing to its constructor the servlet's response parameter. MultipartResponse uses the response object to fetch the servlet's output stream and to set the response's content type.

Then, for each page of content, begin by calling startResponse() passing in the content type for that page. Send the content for the page by writing to the output stream as usual. A call to endResponse() ends the page and flushes the content so the client can see it. At this point a sleep() or other delay can be added until the next page is ready for sending.

The call to endResponse() is optional. The startResponse() method knows whether the last response has been ended, and ends it itself if necessary. However, it's wise to call endResponse() if there's to be a delay between the time one response ends and the next begins. It lets the client display the latest response during the time it waits for the next one.

Finally, after each response page has been sent, a call to the finish() method finishes the multipart response and sends a code telling the client there will be no more responses.

For example:

 MultipartResponse multi = new MultipartResponse(res);
  
 multi.startResponse("text/plain");
 out.println("On your mark");
 multi.endResponse();
  
 try { Thread.sleep(1000); } catch (InterruptedException e) { }
  
 multi.startResponse("text/plain");
 out.println("Get set");
 multi.endResponse();
  
 try { Thread.sleep(1000); } catch (InterruptedException e) { }
  
 multi.startResponse("image/gif");
 ServletUtils.returnFile(req.getRealPath("/images/go.gif"), out);
  
 multi.finish();
 

版本:
1.0, 98/09/18
作者:
Jason Hunter, Copyright © 1998
另请参见:
ServletUtils

构造方法摘要
MultipartResponse(javax.servlet.http.HttpServletResponse response)
          Constructs a new MultipartResponse to send content to the given servlet response.
 
方法摘要
 void endResponse()
          Ends a single response.
 void finish()
          Finishes the multipart response.
 void startResponse(String contentType)
          Begins a single response with the specified content type.
 
从类 java.lang.Object 继承的方法
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

构造方法详细信息

MultipartResponse

public MultipartResponse(javax.servlet.http.HttpServletResponse response)
                  throws IOException
Constructs a new MultipartResponse to send content to the given servlet response.

参数:
response - the servlet response
抛出:
IOException - if an I/O error occurs
方法详细信息

startResponse

public void startResponse(String contentType)
                   throws IOException
Begins a single response with the specified content type. This method knows whether the last response has been ended, and ends it itself if necessary.

参数:
contentType - the content type of this response part
抛出:
IOException - if an I/O error occurs

endResponse

public void endResponse()
                 throws IOException
Ends a single response. Flushes the output.

抛出:
IOException - if an I/O error occurs

finish

public void finish()
            throws IOException
Finishes the multipart response. Sends a code telling the client there will be no more responses and flushes the output.

抛出:
IOException - if an I/O error occurs


Copyright © 2013. All Rights Reserved.