OK, yes, we should be using JSPs rather than sending HTML back in the response output stream from a servlet. Formatting HTML to stick in an output stream’s println() method hurts.
But that doesn’t mean you’ll never have to work with an output stream from your servlet.
1) Your hosting provider might not support JSPs. There are plenty of older servers and containers out there that support servlets but not JSPs, so you’re stuck with it.
2) You don’t have the option of using JSPs for some other reason, like, you have an incredibly stupid manager who won’t let you use JSPs because in 1998 his brother-in-law told him that JSPs were bad.
3) Who said that HTML was the only thing you could send back in a response? You might send something other than HTML back to the client. Something for which an output stream makes perfect sense.
Turn the page for an example...