Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Java > IllegalStateException : Writer being already used by this servlet

Reply
Thread Tools

IllegalStateException : Writer being already used by this servlet

 
 
Kim Ray
Guest
Posts: n/a
 
      02-19-2004
Hi All,
I am faceing a problem (ofcourse thats what makes all of us come
here)..what I am trying to do is , create a image offscreen in a
servlet , then using PixelGrabber serialize the int[] and then the
applet reads it, ..so far fairly straight, now here...
....
....
ObjectOutputStream out = new
ObjectOutputStream(res.getOutputStream());
System.out.println("Inside isReq after out obj");
out.writeInt(w);
out.writeInt(h);
out.writeObject(pixels);
}
/**
try{
res.setContentType("text/html");
printer=res.getWriter();
printer.println("Object Writing done");
printer.close();
}catch(Exception ex){}
}
else{
printer.println("Object Writing <b>Not</b> done");
printer.close();
}**/

After Object writing is being done , I wish to display a html page
(with applet embedded) but using the above code it is giving me a
error "IllegalStateException: Writer being already used by the
servlet..."
Can anyone help me out...

Regards
Ray
 
Reply With Quote
 
 
 
 
Tony Morris
Guest
Posts: n/a
 
      02-19-2004

"Kim Ray" <> wrote in message
news: m...
> Hi All,
> I am faceing a problem (ofcourse thats what makes all of us come
> here)..what I am trying to do is , create a image offscreen in a
> servlet , then using PixelGrabber serialize the int[] and then the
> applet reads it, ..so far fairly straight, now here...
> ...
> ...
> ObjectOutputStream out = new
> ObjectOutputStream(res.getOutputStream());
> System.out.println("Inside isReq after out obj");
> out.writeInt(w);
> out.writeInt(h);
> out.writeObject(pixels);
> }
> /**
> try{
> res.setContentType("text/html");
> printer=res.getWriter();
> printer.println("Object Writing done");
> printer.close();
> }catch(Exception ex){}
> }
> else{
> printer.println("Object Writing <b>Not</b> done");
> printer.close();
> }**/
>
> After Object writing is being done , I wish to display a html page
> (with applet embedded) but using the above code it is giving me a
> error "IllegalStateException: Writer being already used by the
> servlet..."
> Can anyone help me out...
>
> Regards
> Ray


Read the API documentation
You can't call HttpServletResponse#getWriter() after a call to
HttpServletResponse#getOutputStream()
and there's a good reason for that (more in-depth thought required on your
part).

It is very unclear what you are trying to achieve, so I can't offer a
correct solution.

PS:
catch(java.lang.Exception e) // this piece of code *should* result in
castration (unless the Exception is rethrown) - it's poor form

--
Tony Morris
(BInfTech, Cert 3 I.T.)
Software Engineer
(2003 VTR1000F)
Sun Certified Programmer for the Java 2 Platform (1.4)
Sun Certified Developer for the Java 2 Platform


 
Reply With Quote
 
 
 
 
Kim Ray
Guest
Posts: n/a
 
      02-19-2004
Hi Tony
Thanks for the response , here is what I am doing,
1) I have an Applet which takes user input as text.
2) From applet it passes simple parameters to the servlet using the
showDocument method showDocument("http://server/webapp/ServletName?text1=text1&text2=text....")
3) The servlet gets the parameters and constructs images out of those
text using customer defined fonts (from Font.createFont() methods)
4)Using PixelGrabber the image is serialized as int[] to the response
stream

Now....
A) After serialization I want to reload the applet so that it
de-serializes the int[] and reconstruct the image (The reconstruction
of image and displaying it on applet is working fine , when i run the
servlet as a standalone (with no user input)), but when I take the
user input ...here is what the problem comes

Regards
Ray
"Tony Morris" <> wrote in message news:<c11ef7$kq0$>...
> "Kim Ray" <> wrote in message
> news: m...
> > Hi All,
> > I am faceing a problem (ofcourse thats what makes all of us come
> > here)..what I am trying to do is , create a image offscreen in a
> > servlet , then using PixelGrabber serialize the int[] and then the
> > applet reads it, ..so far fairly straight, now here...
> > ...
> > ...
> > ObjectOutputStream out = new
> > ObjectOutputStream(res.getOutputStream());
> > System.out.println("Inside isReq after out obj");
> > out.writeInt(w);
> > out.writeInt(h);
> > out.writeObject(pixels);
> > }
> > /**
> > try{
> > res.setContentType("text/html");
> > printer=res.getWriter();
> > printer.println("Object Writing done");
> > printer.close();
> > }catch(Exception ex){}
> > }
> > else{
> > printer.println("Object Writing <b>Not</b> done");
> > printer.close();
> > }**/
> >
> > After Object writing is being done , I wish to display a html page
> > (with applet embedded) but using the above code it is giving me a
> > error "IllegalStateException: Writer being already used by the
> > servlet..."
> > Can anyone help me out...
> >
> > Regards
> > Ray

>
> Read the API documentation
> You can't call HttpServletResponse#getWriter() after a call to
> HttpServletResponse#getOutputStream()
> and there's a good reason for that (more in-depth thought required on your
> part).
>
> It is very unclear what you are trying to achieve, so I can't offer a
> correct solution.
>
> PS:
> catch(java.lang.Exception e) // this piece of code *should* result in
> castration (unless the Exception is rethrown) - it's poor form

 
Reply With Quote
 
Tony Morris
Guest
Posts: n/a
 
      02-19-2004
"Kim Ray" <> wrote in message
news: om...
> Hi Tony
> Thanks for the response , here is what I am doing,
> 1) I have an Applet which takes user input as text.
> 2) From applet it passes simple parameters to the servlet using the
> showDocument method

showDocument("http://server/webapp/ServletName?text1=text1&text2=text....")
> 3) The servlet gets the parameters and constructs images out of those
> text using customer defined fonts (from Font.createFont() methods)
> 4)Using PixelGrabber the image is serialized as int[] to the response
> stream
>
> Now....
> A) After serialization I want to reload the applet so that it
> de-serializes the int[] and reconstruct the image (The reconstruction
> of image and displaying it on applet is working fine , when i run the
> servlet as a standalone (with no user input)), but when I take the
> user input ...here is what the problem comes
>
> Regards
> Ray
> "Tony Morris" <> wrote in message

news:<c11ef7$kq0$>...
> > "Kim Ray" <> wrote in message
> > news: m...
> > > Hi All,
> > > I am faceing a problem (ofcourse thats what makes all of us come
> > > here)..what I am trying to do is , create a image offscreen in a
> > > servlet , then using PixelGrabber serialize the int[] and then the
> > > applet reads it, ..so far fairly straight, now here...
> > > ...
> > > ...
> > > ObjectOutputStream out = new
> > > ObjectOutputStream(res.getOutputStream());
> > > System.out.println("Inside isReq after out obj");
> > > out.writeInt(w);
> > > out.writeInt(h);
> > > out.writeObject(pixels);
> > > }
> > > /**
> > > try{
> > > res.setContentType("text/html");
> > > printer=res.getWriter();
> > > printer.println("Object Writing done");
> > > printer.close();
> > > }catch(Exception ex){}
> > > }
> > > else{
> > > printer.println("Object Writing <b>Not</b> done");
> > > printer.close();
> > > }**/
> > >
> > > After Object writing is being done , I wish to display a html page
> > > (with applet embedded) but using the above code it is giving me a
> > > error "IllegalStateException: Writer being already used by the
> > > servlet..."
> > > Can anyone help me out...
> > >
> > > Regards
> > > Ray

> >
> > Read the API documentation
> > You can't call HttpServletResponse#getWriter() after a call to
> > HttpServletResponse#getOutputStream()
> > and there's a good reason for that (more in-depth thought required on

your
> > part).
> >
> > It is very unclear what you are trying to achieve, so I can't offer a
> > correct solution.
> >
> > PS:
> > catch(java.lang.Exception e) // this piece of code *should* result in
> > castration (unless the Exception is rethrown) - it's poor form


If that is the case, simply use two servlets to perform each task - the
applet should request from each individually.

--
Tony Morris
(BInfTech, Cert 3 I.T.)
Software Engineer
(2003 VTR1000F)
Sun Certified Programmer for the Java 2 Platform (1.4)
Sun Certified Developer for the Java 2 Platform


 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Servlet.service() for servlet jsp threw exception java.lang.IllegalStateException: getOutputStream() has already been called for this response javadev Java 5 11-16-2006 11:22 AM
IllegalStateException: OutputStream already obtained vsingr Java 0 06-26-2006 04:31 PM
[Crystal Reports] IllegalStateException: OutputStream already retrieved Alexandre Touret Java 1 06-08-2005 03:55 PM
Isn't DataGrid.Render(writer) supposed to automatically call RenderBeginTag(writer) and RenderEndTag(writer)? Henri ASP .Net Building Controls 1 07-13-2004 10:27 PM
Writer being already used by this servlet : IllegalStateException Kim Ray Java 1 02-18-2004 12:50 PM



Advertisments