There are two problems with above code. 1) The request is forwarded after committing the response. This will result into IlligalStateException. In the book it is mentioned. 2) The other is with the line marked Erroneous. Here getResourceAsStream() method accepts string parameter. But the URL path should start with '/' i.e. it will search in and from root.
I’ve looked at a lot of different solutions, and in my humble opinion Aspose is the way to go. Here’s the link: http://aspose.com