• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Effect of Calling setContextType() more than once

 
Sandeep Vaid
Ranch Hand
Posts: 392
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator


What will be the effect?

1. Some Exception?
2. Statement A) will be effective
3. Statement B) will be effective

I know it's not practically correct but what will be the output in this case ?
 
Ulf Dittmer
Rancher
Posts: 42969
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
That's quite easy to test, isn't it?
 
Tridib Samanta
Ranch Hand
Posts: 128
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Statement B will be effective.

According to servlet specification:
This method may be called repeatedly to change content type and character
encoding. This method has no effect if called after the response has been
committed.


As nothing has been written to the output stream and flush method has not been called, so the response is not commited.
[ March 24, 2007: Message edited by: Tridib Samanta ]
 
arun shanmugam kumar
Greenhorn
Posts: 25
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

Statement B will not have any effect according to page 46 and 47 of the servlet spec 2.4.

If setContentType method is not called before calling getWriter or if the response is committed then default ISO-8859-1 is used.
 
Sergio Tridente
Ranch Hand
Posts: 329
Java Linux Oracle
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If setContentType method is not called before calling getWriter or if the response is committed then default ISO-8859-1 is used.


It is only the character encoding that will take no effect, but the content type will be changed (unless you commited the response before).

I've just tried:

And the result I get is a "text/html" page that uses the UTF-8 encoding.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic