Discussions

Web tier: servlets, JSP, Web frameworks: Opening a binary stream o/p to client from jsp

  1. A JSP page is compiled into a Servlet; therefore, it can do everything that a Servlet can do.
    However, why is an IllegalStateException thrown when opening a Binary Stream output to the client from a JSP page but NOT to a Servlet?

    Please explain

    Select answer from below
    Choice 1
     JSP pages can write a Binary Stream using its implicit out stream.
    Choice 2
     JSP pages use a different Streaming mechanism to Servlets.
    Choice 3
     JSP pages have more security settings than Servlets.
    Choice 4
     JSP has already opened the stream as a JspWriter.
    Choice 5
     JSP pages must flush their buffers before changing the stream type; Servlets do not have this limitation.
  2. coz'

    JSP has already opened the stream as a JspWriter

    where as i know, servlet can't give its output simultaneously in the char-bin stream. once you start streaming characters, you can't stream binary data. JSPs are always converted to servlets and then compiled. as soon as you write the <html> tag in your JSP, JspWriter is open, and now you can't sream binary. the best idea is, use dedicated servlets which streams desired binary for you, and call them from withing a JSP whenever the binary data is requiered.

    hope this helps you :)