ServltInputStream provides stream to read binary data from request object - Servlets

Q.  Which class provides stream to read binary data such as image etc. from the request object?
- Published on 22 Jul 15

a. ServltInputStream
b. ServletOutputStream
c. Both A & B
d. None of the above

ANSWER: ServltInputStream
 

    Discussion

  • Nirja Shah   -Posted on 15 Dec 15
    ServletInputStream class
    - This class provides stream to read binary data such as image etc. from the request object. It is an abstract class.
    The getInputStream() method of ServletRequest interface returns the instance of ServletInputStream class. So we can write down as follows:
    ServletInputStream sin=request.getInputStream();

    - Method of ServletInputStream class
    There are only one method defined in the ServletInputStream class.
    1. int readLine(byte[] b, int off, int len) it reads the input stream.

    ServletOutputStream class
    - This class provides a stream to write binary data into the response. It is an abstract class.
    - The getOutputStream() method of ServletResponse interface returns the instance of ServletOutputStream class. It may be get as:
    1. ServletOutputStream out=response.getOutputStream();

    - Methods of ServletOutputStream class
    The ServletOutputStream class provides print() and println() methods that are overloaded.
    1. void print(boolean b){}
    2. void print(char c){}
    3. void print(int i){}
    4. void print(long l){}
    5. void print(float f){}
    6. void print(double d){}
    7. void print(String s){}
    8. void println{}
    9. void println(boolean b){}
    10. void println(char c){}
    11. void println(int i){}
    12. void println(long l){}
    13. void println(float f){}
    14. void println(double d){}
    15. void println(String s){}

Post your comment / Share knowledge


Enter the code shown above:

(Note: If you cannot read the numbers in the above image, reload the page to generate a new one.)