This week's book giveaway is in the General Computing forum. We're giving away four copies of Arduino in Action and have Martin Evans, Joshua Noble, and Jordan Hochenbaum on-line! See this thread for details.
Hi all, I have a question about setContentType() and getOutputStream(), getWriter(). setContentType() should be called before calling getWriter(), as is said on the API spec. Should we call setContentType() before calling getOutputStream() too? Thanks! Kyle
There is always a need to set the content type, especially when writing binary data. After all, if you just present the browser with a splotch of binary gloop, how is it supposed to know whether it's a JPEG image (image/jpeg), GIF image (image/gif), PNG image (image/png), AVI movie, QuickTime movie, MIDI file, Word document, or some format it doesn't know and needs to pop up a "Save As..." dialog box for? - Peter
Peter is right. Givin� an additional information: if you don�t specify the method setContentType, the type "text/html" will be evaluated automatically keep studying
Kyle Tang
Ranch Hand
Joined: Aug 22, 2002
Posts: 78
posted
0
Thanks guys! My understanding now is, 1. if need to call setContentType() and getWriter(), then always call setContentType() first. The reason is setContentType() may change the charset, which affect the PrintWriter. 2. setContentType() doesn not need to be called before calling getOutputStream() 3. if no setContentType() called, content type is "text/html;charset=iso-8859-1". Kyle
Peter den Haan
author
Ranch Hand
Joined: Apr 20, 2000
Posts: 3252
posted
0
Thanks for the summary Kyle. I believe I may have misinterpreted RP's reply -- rereading this thread, it is clear that he meant there is no need to call setContentType before calling getOutputStream(). Which is correct (although you should call it before writing any great quantities of data to this stream; in fact it is good style to set the content type before writing any data to the output stream). - Peter