8 messages in com.mysql.lists.javaRe: How to stop a servlet| From | Sent On | Attachments |
|---|---|---|
| Emanuel Dejanu | 25 Jan 2000 08:00 | |
| LEBLANC, CLAUDE | 25 Jan 2000 12:41 | |
| Mark Matthews | 25 Jan 2000 13:25 | |
| john gregg | 25 Jan 2000 15:43 | |
| LEBLANC, CLAUDE | 15 May 2000 11:17 | |
| Tim Endres | 15 May 2000 12:40 | |
| LEBLANC, CLAUDE | 16 May 2000 12:00 | |
| Christian Mack | 23 May 2000 23:01 |
| Subject: | Re: How to stop a servlet![]() |
|---|---|
| From: | Christian Mack (mack...@gmx.de) |
| Date: | 05/23/2000 11:01:38 PM |
| List: | com.mysql.lists.java |
Hi Claude
No, they are not totally the same.
The PrintWriter provides automatically conversion between different
charactersets.
This isn't necessary as long as you only use the ASCII-characters.
Tschau Christian
"LEBLANC, CLAUDE" wrote:
Yes, I want to catch the exception in case the user goes back or stops a long query.
The API documentation probably confused me when I wrote my first "HelloWorld" servlet because it says that one is for text output and the other is for binary data. So I used PrintWriter to write my string and stuck with it.
From documentation : public ServletOutputStream getOutputStream() Returns a ServletOutputStream suitable for writing binary data in the response.
public java.io.PrintWriter getWriter() Returns a PrintWriter object that you can use to send character text to the client.
Apparently there is no diference for output once res.setContentType("text/html") has been called. Am I right?
Thanks. Claude
Tim Endres wrote:
PrintWriter does not throw the exception, however, it should be setting the error flag, so checkError() should indicate the socket close, but I have never tested this directly.
As for why, well, many things take PrintWriter as their input, so that is probably the primary reason for using it. Another might be that some folks actually want to eliminate the IOExceptions so they can ignore them.
If you wish to catch the IOException, I would stick to the ServletOutputStream.
tim.
Ok, I'm back to this problem...
Thanks Mark for your reply. I've been reading here and there about servlets programming and found out the following (from Servlet programming, J.Hunter):
If the servlet uses PrintWriter out = res.getWriter(); it will not throw an exception,
but using ServletOutputStream out = res.getOutputStream(); will throw an exception when the client is not listening anymore (which should fix my problem).
However, from the examples I saw I don't understand completly why or when one would use PrinterWriter or ServletOutputStream object ?
Could you (and/or others) give me some comments or guide lines on this! Thanks a lot.
Claude




