David Roussel

Greenhorn
+ Follow
since Aug 01, 2001
Merit badge: grant badges
For More
Cows and Likes
Cows
Total received
0
In last 30 days
0
Total given
0
Likes
Total received
0
Received in last 30 days
0
Total given
0
Given in last 30 days
0
Forums and Threads
Scavenger Hunt
expand Ranch Hand Scavenger Hunt
expand Greenhorn Scavenger Hunt

Recent posts by David Roussel

The solution to this problem, and which is good practice anyway, is to use a servlet as the entry to parts of your application. Then use the RequestDispatcher to forward on to your JSPs to give the view.
For instance accessing the url /myapp/admin?cmd=add.user will invoke the admin servlet. The servlet checks the users login, creates the beans needed on the addUser.jsp page, adds then beans to the request context and does the gzip wrapping (explained in a moment). If any error occurs forward the request to error.jsp, otherwise forward the request to the correct jsp, as determined by the cmd page parameter.
The trick to getting the output stream compression to work is that RequestDispatcher.forward() allows you to pass in your own ServletResponse. All you have to do is create your own class that implements ServletResponse to warp the original ServletResquest. Each method should just delegate to the wrapped object, except the getOutputStream() method which should do all the compression set described further up this thread.

If you don't want to have servlets as the entry point to your web app, then you can make use of the JSP extends directive. This directive should be placed at the top of each JSP page and instructs the JSP compiler to use a give class as the base class of the generated page servlet. From this base class you then have all the hooks to add in output stream compression for a JSP transparently to the JSP. See any JSP tutorial for how to use the extends directive.
I hope this helps.
David Roussel
22 years ago