Steve: An HTTP response may only have one content type. If you wish to send multiple documents of different types to the client in a single HTTP response. One way to do this is to set the content type to multipart/mixed, and encode your messages as follows:
Content-type: multipart/mixed; boundary=END-OF-SECTION --END-OF-SECTION Content-type: text/html <html><head> <title>Downloading to Disk</title> </head> <body> <h1>Downloading to Disk</h1> The files "foobar.test" and "foobar2.test" are being downloaded to your system. Please read the license agreement carefully. --END-OF-SECTION Content-type: application/octet-stream Content-disposition: filename="foobar.test" ...The contents of "foobar.test" goes here... --END-OF-SECTION Content-type: application/octet-stream Content-disposition: filename="foobar2.test" ...The contents of "foobar2.test" goes here... --END-OF-SECTION-- Your application will will need to deal with break apart the individual mime documents. There are some classes that will help you with this in javax.mail.* and javax.mail.internet.*; I think you'll find this in the Java mail api (which you can download from sun). I hope this helps. Tom Drake ----- Original Message ----- From: "Ball, Steve" <[EMAIL PROTECTED]> To: <[EMAIL PROTECTED]> Cc: <[EMAIL PROTECTED]>; <[EMAIL PROTECTED]>; <[EMAIL PROTECTED]> Sent: Thursday, November 29, 2001 6:45 AM Subject: mutipart/x-mixed-replace and HttpURLConnection | I am working on "Server Push" from a Servlet to a Java client using | HttpURLConnection. I am attempting to set the boundaries and set the other | mime types in my servlet, but my client seems to only understand the first | call using .setContentType(""); Is what I am doing even feasible? Any tips | would be much appreciated. | | ++++++++++++++++++++ | client | ++++++++++++++++++++ | URLConnection con = url.openConnection(); | con.setDoOutput(true); | con.setDoInput(true); | con.setUseCaches(false); | ((HttpURLConnection)con).setRequestMethod("POST"); | ((HttpURLConnection)con).setRequestProperty("Connection", | "Keep-Alive"); | ((HttpURLConnection)con).setRequestProperty("Content-type", | "multipart/x-mixed-replace; boundary=End"); | | . | . | . | . | | String header = con.getContentType(); | System.out.println("Header:" + header); | if (header.equals("text/start")) | { | start = con.getContent(); | System.out.println("Actual Content:" + (String)start); | } | else if (header.equals("text/file")) | { | file = con.getContent(); | System.out.println((String)file); | } | else if (header.equals("text/file-progress")) | { | fileprogress = con.getContent(); | System.out.println((String)fileprogress); | } | else if (header.equals("text/end")) | { | end = con.getContent(); | System.out.println((String)end); | keep_reading = false; | } | else | { | System.out.println("Unknown Content Type: " + header); | Object obj = con.getContent(); | if (obj != null) | System.out.println("Something is there"); | else | System.out.println("Nothing is in there"); | | | ++++++++++++++++++++ | server | ++++++++++++++++++++ | | | ServletOutputStream out = res.getOutputStream(); | res.setContentType("multipart/x-mixed-replace; boundary=End"); | out.println(); | out.println("--End"); | | out.println("Content-Type: " + "text/start"); | out.println(); | StringBuffer startCommand = new StringBuffer(); | startCommand.append("Start Data"); | | //res.setContentType("text/start"); | res.setContentLength(startCommand.toString().getBytes().length + 55); | out.print(startCommand.toString()); | out.println(); | out.println("--End"); | out.flush(); | | | | Basically, the current behavior of the client is that it is looping around | and gets from the server only the mime type set using setContentType(); | which in this case is only multipart/x-mixed-replace type. The content | types set using the out.println("Content-Type: " + "text/start"); are | ignored. By the way, I am supporting my own mime types and that appears to | work okay. The content type which does seem to appear rather than | x-mixed-replace is a class called sun.net.www.MeteredStream. As I said | earlier, any help would be much appreciated. | | Thanks, | Steve | | -- | To unsubscribe: <mailto:[EMAIL PROTECTED]> | For additional commands: <mailto:[EMAIL PROTECTED]> | Troubles with the list: <mailto:[EMAIL PROTECTED]> | | | -- To unsubscribe: <mailto:[EMAIL PROTECTED]> For additional commands: <mailto:[EMAIL PROTECTED]> Troubles with the list: <mailto:[EMAIL PROTECTED]>