|
 |
pro_jsp thread: Conflicts between OutputStream and PrintWriter
Message #1 by "Hosea Ho" <comitdo@y...> on Fri, 10 Jan 2003 12:49:10
|
|
Continuing...
Doing some research, I found that IE does not support multipart messages, so
end user using IE can eventualy only download the response (default action
when unknown type for IE), but Netscape does. So try you jsp using Netscape.
The second ideea is you can try using also "parallel" subtype of the
"multipart" type. Replace the line:
response.setContentType("multipart/x-mixed-replace;boundary=aaa");
with the line:
response.setContentType("multipart/parallel;boundary=aaa");
This way the parts will not be displayed one by one, next replacing
previous, but simultaneously.
Cheers,
Catalin
----- Original Message -----
From: "Catalin Ignat" <cignat@s...>
To: "Pro_JavaServer_Pages" <pro_jsp@p...>
Sent: Monday, January 13, 2003 12:17 PM
Subject: [pro_jsp] Re: Conflicts between OutputStream and PrintWriter
> Hello,
>
> My mistake about previus response, I do not understand entirely your
> question.
>
> About writing text and image at the same time to the client browser, I do
> not know a way to achieve this, and client seen on the page text and image
> also.
> Anyway, you can use so-called technique "server-push", this is very
similar
> to what email use when sending multipart messages.
>
> However, this technique was used on video stream (slow performance), or
some
> animation.
> You can try the following code, and find extra documentation on the web.
>
> //start code*****************************************************
> try{
> response.setContentType("multipart/x-mixed-replace;boundary=aaa");
> ServletOutputStream os = response.getOutputStream();
>
> os.println("--aaa");
> os.println("Content-Type: text/plain");
> os.println();
>
> String str = "PICTURE picture";
> os.write(str.getBytes(), 0, str.length());
> os.flush();
>
> try {
> Thread.sleep(1000);
> } catch (InterruptedException e) { }
>
> os.println("--aaa");
> os.println("Content-Type: image/jpeg");
> os.println();
>
> //read image from file via InputStream
> File f = new File("C:\\triangle.jpg");
> InputStream is = new FileInputStream(f);
> final int LEN = 2048;
> byte[] buffer = new byte[LEN];
> int readed;
>
> //suppose to write to browser image
> while((readed = is.read(buffer, 0, LEN)) != -1){
> os.write(buffer, 0, readed);
> }
> os.flush();
>
> try {
> Thread.sleep(1000);
> } catch (InterruptedException e) { }
>
> os.println("--aaa--");
> os.flush();
>
> Hope it helps,
> Catalin
>
>
> //end code*****************************************************
>
> ----- Original Message -----
> From: "Ho Derossi" <comitdo@y...>
> To: "Pro_JavaServer_Pages" <pro_jsp@p...>
> Sent: Saturday, January 11, 2003 7:24 PM
> Subject: [pro_jsp] Re: Conflicts between OutputStream and PrintWriter
>
>
> > Hello,
> >
> > thanks for the advice on the use of getBytes().
> > I need only use OutputStream to write text and image
> > to browser in jsp page.
> >
> > Below is the jsp code I use for the jsp page. However,
> > I am unable to get the browser to display both text
> > and image.
> >
> > /*****************CODE BEGIN**************/
> >
> > <%@ page import="java.io.*" %>
> >
> > <%
> > try{
> > response.setContentType("text/html");
> > OutputStream os = response.getOutputStream();
> >
> > String str = "PICTURE picture";
> > byte[] strByte = str.getBytes("ISO-8859-1");
> >
> > //write to browser to display text "PICTURE picture"
> > for(int x=0; x<strByte.length; x++){
> > os.write(strByte[x]);
> > }
> >
> >
> > //read image from file via InputStream
> > File f = new File("C:\\triangle.jpg");
> > InputStream is = new FileInputStream(f);
> > byte[] buffer = new byte[is.available()];
> >
> > //suppose to write to browser image
> > int num = is.read();
> > while(num!=-1){
> > os.write(num);
> > num = is.read();
> > }
> >
> > os.flush();
> > }
> > catch(FileNotFoundException fnfe){
> > System.out.println("File NOT found." + fnfe);
> > }
> > catch(IOException ioe){
> > System.out.println("IOException took place : " +
> > ioe);
> > }
> > %>
> >
> > /*******************CODE END********************/
> >
> > Instead, I get displays of text and image as text
> > formats.
> > example of browser display :
> >
> > PICTURE picture
> > $.' ",#(7),01444'9=82<.342
> > 2!!
> >
> >
> >
> > How do I overcome these problem?
> >
> > thank you
> > Hosea
> >
> >
> > --- Catalin Ignat <cignat@s...> wrote:
> > > Hello,
> > >
> > > With OutputStream, you can flush text as byte array,
> > > using getBytes()
> > > function of the String objects.
> > >
> > > Catalin
> > >
> > > ----- Original Message -----
> > > From: "Hosea Ho" <comitdo@y...>
> > > To: "Pro_JavaServer_Pages" <pro_jsp@p...>
> > > Sent: Friday, January 10, 2003 12:49 PM
> > > Subject: [pro_jsp] Conflicts between OutputStream
> > > and PrintWriter
> > >
> > >
> > > > Objective : to write a JSP or servlet page that is
> > > able to send both image
> > > > and text to the browser without the conflicts
> > > between OutputStream and
> > > > PrintWriter. This is because you can only use
> > > either OutputStream or
> > > > PrintWriter to write the response and not both.
> > > >
> > > > I am able to write image from database on JSp page
> > > or servlet page and
> > > > seperately text to another JSP page or servlet.
> > > But I can't combine them
> > > > both.
> > > >
> > > > How do I get around the conflicts
> > > >
> > > > grateful & thanks
> > > > Hosea
> > >
> > >
> >
> >
> > __________________________________________________
> > Do you Yahoo!?
> > Yahoo! Mail Plus - Powerful. Affordable. Sign up now.
> > http://mailplus.yahoo.com
> >
>
>
|
|
 |