41 Advanced java Servlet Tutorial | Understanding OOPS Related to response setContentType text html

Published: 05 February 2018
on channel: Programming
1,013
127

Advanced java Servlet Tutorial | #Understanding OOPS Related to respo.setContentType("text/html");?
'respo' is response object, nothing but the object of underlaying container supplied java class that impelements javax.servlet.ServletReponse interface directly or indirectly.

setContentType(-) method is declared in javax.servlet.ServletResponse interface like
public void setContentType(String contentType);

in the definition of setContentType(-) logic is available to give instruction to browser window regarding response content type through server.

This method definition is availbale in conatiner supplied java class that implements javax.servlet.ServletResponse interface.

Note: In Tomcat implementation class name of ServletResponse is (availble in catelina.jar):org.apache.catalina.connector.ResponseFacade

In Tomcat implementation class name of ServletRequest is (availble in catelina.jar):org.apache.catalina.connector.RequestFacade

Pointing to response object we can have one of the following two types of streams :

1) PrintWriter Stream
2) ServletOutputStrem

1) PrintWriter Stream: It is a character stream.

Useful to write webpages that contains more text data(char data) & less image page (byte data)

PrintWriter pw=response.getWriter();
pw.println("Hello world");

2) ServletOutputStream: It is a byte stream.
Useful to write web pages that contains more images(byte data )and less text data (char data)

ServletOutputStream sos=response.getOutputStream();
sos.println("Hello World");

Note : We can not use both streams at a time in servlet program.


On this page of the site you can watch the video online 41 Advanced java Servlet Tutorial | Understanding OOPS Related to response setContentType text html with a duration of hours minute second in good quality, which was uploaded by the user Programming 05 February 2018, share the link with friends and acquaintances, this video has already been watched 1,013 times on youtube and it was liked by 127 viewers. Enjoy your viewing!