Explain why contentType has to be set BEFORE accessing the PrintWriter object.
Servlet container may commit the response output to the client when the response buffer is filled. But the servlet container providers may choose not to implement buffering at all. See the following quote from Servlet Spec 2.4 Section SRV.5.1 page 43.
From Spec
So, if as a servlet developer you are not setting the content type before writing to your output stream the container may commit the response and subsequently your call for setting the content-type will be ignored by the container as the response has already been committed.
0 Comments:
Post a Comment
<< Home