O'Reilly logo

Head First Servlets and JSP, 2nd Edition by Bert Bates, Bryan Basham, Kathy Sierra

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Using the response for I/O

image with no caption

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.

Why?

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...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required