Win a copy of The Little Book of Impediments (e-book only) this week in the Agile and Other Processes forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

A javaprepare.com question

 
Jingh Yi
Ranch Hand
Posts: 90
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Name the method defined in the HttpServletResponse class that may be used to set the content type. Do not include parenthesis after the method.

The answer is setContentType.

But I think setHeader is also right. We can have HttpServletResponse.setHeader("Content-Type", "text/html"). Right?

Thanks!
Jenny
 
alex Bell
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Jingh Yin:
Name the method defined in the HttpServletResponse class that may be used to set the content type. Do not include parenthesis after the method.

The answer is setContentType.

But I think setHeader is also right. We can have HttpServletResponse.setHeader("Content-Type", "text/html"). Right?

Thanks!
Jenny


I don't think so,in my opinion,setContentType affects how the server deals the response data,as a example,to take the data retrieved from DB as binary stream instead of ASCII, while setHeader affect how the web browser deals the received document,is a html or a media file.
alex
 
Nag RM
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I feel both are correct.
Both ServletResponse.setContentType() and HTTPServletResponse.setHeader ("Content-Type", val) sets the �Content-Type� Entity Header.
The web server should implement the ServletResponse.setContentType() and HTTPServletResponse.setHeader() in such a way that they sets the �Content-Type� HTTP header.
The URL http://mail-archives.apache.org/mod_mbox/jakarta-tomcat-dev/200003.mbox/%3c38E17162.BC770A69@eng.sun.com%3e tells that Tomcat 3 ignors setContentType(), but not the other web servers.

(�Content-Type� is a Entity Header that Indicates the media type of the data sent to the recipient or, in the case of the HEAD method, the media type that would have been sent had the request been a GET. )

----------------------
Nag
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic