IllegalStateException : Writer being already used by this servlet

K

Kim Ray

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
 
T

Tony Morris

Kim Ray said:
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
 
K

Kim Ray

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 said:
Kim Ray said:
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
 
T

Tony Morris

Kim Ray said:
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" <[email protected]> wrote in message
Kim Ray said:
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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,768
Messages
2,569,574
Members
45,051
Latest member
CarleyMcCr

Latest Threads

Top