Reidar Gjerstad wrote:Wouldn't it be useful to be able to set and remove attributes in the Response as well?
After all both the request and response objects are included when forwarding to another servlet or a JSP:
You are correct - both request and response objects are included on forwarding the request among the components. That means request and response objects live together, so having a response scope isn't worth because whatever you are going to add to a "response scope", can instead be added to the request scope with no difference.
I understand that one scope is enough since you can do everything necessary with it.
So I guess that the spec developers could equally well have decided to specify a Response scope in stead of the Request scope and giving Response scope all the setters and getters that Request has today, but that they decided that Response would be more natural to use.
There is no Response scope becouse servlets take "input" and generate "output" and give that job to the next servlet so there is no sense in putting variables like into a scope to the "output" of the next servlet but to the "input".
- it's not about that that one scope is enough to do everything necessary with it.
- developers could make such a decision but that would be wrong decision.
- having a response scope isn't worth not becouse request scope does the job, but becouse if there would be a response scope, it wouldn't be called response any more. ( I can bet on that. )
- It is possible to extend HttpServletResponse class, and to make a Response scope.... (maybe)
In my "Response scope" I would put a Tetris engine and somehow connect it to my desktop java application so that I can play tetris knowing that the Tetris engine is in a HttpServletResponse object on the servlet. The advantage would be: fun, experiment, knowledge, joke, good will, nice day, tetris, etc..
Now I just have to invent how to make a connection to my desktop GUI application, probablly over the Socket, why not? And also, how to slow down the request processing. And probablly how to pass over and over again the same response object back into a game so that my session does't stop.
Petar Tomičić wrote:It is possible to extend HttpServletResponse class, and to make a Response scope.... (maybe)
No, HttpServletResponse in an interface - not a class. The class of the object which is being passed to the service method depends on the container implementation. Even if you extend that class, or implement HttpServletResponse, the container will not instantiate it as it has its own implementation.