aspose file tools*
The moose likes Web Component Certification (SCWCD/OCPJWCD) and the fly likes Is setContentType() optional? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Soft Skills this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Certification » Web Component Certification (SCWCD/OCPJWCD)
Bookmark "Is setContentType() optional?" Watch "Is setContentType() optional?" New topic
Author

Is setContentType() optional?

James Kwan
Ranch Hand

Joined: Dec 06, 2001
Posts: 51
Does anyone know if setContentType() needs to always be called to set the content type for the response prior to calling getWriter(). If not, what is the default setting or will there be an exception thrown?
Madhav Lakkapragada
Ranch Hand

Joined: Jun 03, 2000
Posts: 5040
I am not too sure abt servlets, but in JSPs the Specs say that it is optional. The default for JSPs is "text/html".
Will update on servlets as I find out.....
- satya


Take a Minute, Donate an Hour, Change a Life
http://www.ashanet.org/workanhour/2006/?r=Javaranch_ML&a=81
Meng Tan
Ranch Hand

Joined: Jan 20, 2001
Posts: 115
I think it may be server dependent.
Srini Admala
Ranch Hand

Joined: Dec 04, 2001
Posts: 50
While using servlets, setContentType() has to be explicitly done before getting the PrintWriter.
////////// code ///////////////////////
response.setContentType("text/html");
PrintWriter out = response.getWriter();
////////////////////////////////////////
And in Jsp's contentType is by default "text/html" for page directive.

Hope this helps.
-Srini
Stephen Tallamy
Greenhorn

Joined: Jan 08, 2002
Posts: 16
I'm not sure if setContentType() HAS to be called, although it is preferrable. I've developed a Servlet without it and it runs in Tomcat fine. It does produce some rather odd results though, as sometimes it the font of the text changes.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Is setContentType() optional?