File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

setContentType

 
Kalpesh Soni
Ranch Hand
Posts: 312
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
1) what if i do not write response.setContentType() ?
2) what if i write response.setContentType() at the end of the doGet() method ??
As I understand , the servlet starts flushing its buffer so say i have 20k of data is servlet, 1k will be flushed when available and next and next
now after browser gets 20k data i am sending content type. so how will the browser show it ?
 
Barry Gaunt
Ranch Hand
Posts: 7729
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
According to the API you must always call setContentType() (if you do call it, that is) before getting a PrintWriter with getWriter().
When I did not do it, I got my HTML rendered as plain text by my browser. Calling setContentType( "text/html" ) enabled the correct rendering.
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 64173
83
IntelliJ IDE Java jQuery Mac Mac OS X
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It is browser-specific what content type the browser will assume if you do not specify it. So as Barry pointerd out, it's best to be sure and set it so you get correct behavior on the client side.
hth,
bear
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic