• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Does

 
Elier Rguez
Ranch Hand
Posts: 30
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

I can't understand well the steps 2-b and 2-c in this process:



I coded this filter and I was able to modify the response object after chain.doFilter(req, resp) was called, just before it went back to the Container



Servlet sample 1:

Output:
Filter_1->after chain.doFilter

I was able to remove the content of the response object that was inserted in the servlet.


Servlet sample 2:

Output:
- FilterServletTest
- after flush in Servlet

In this second example I wasn't able to modify the resp object. I think it is for calling the flush() method in the servlet, but if this is the reason, why after flush method the second println " - after flush in Servlet" could be inserted?

I think the reason of my misunderstanding is that I don't understand well what flush() ("Flushes the stream") method imply.


Thanks for your explanation,
 
Jeanne Boyarsky
author & internet detective
Marshal
Posts: 35276
384
Eclipse IDE Java VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Eller,
Good question. Normally, you can call flush() as many times as you want. It is a way to tell the container. ""hey, send this along to the client now while I finish working". Kind of like an assembly line. You can keep working the line after the first item is returned.

In the example from the book, all of the output needs to be compressed. Which means it all needs to exist at the same time and not be sent along in pieces. Imagine we wanted to put all the assembly line output in a box. We wouldn't want each to be sent out as long as it was done. We'd want to collect it.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic