• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Why isn't there a Response scope?

 
Reidar Gjerstad
Greenhorn
Posts: 19
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Fellow ranchers

There are no stupid questions..., but perhaps this one is.

In the servlet world there are three scopes: Context, Request and Session.

-Why isn't there a scope called Response?

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



Cheers
 
Devaka Cooray
Marshal
Pie
Posts: 4879
402
Chrome Eclipse IDE Google App Engine IntelliJ IDE jQuery Postgres Database Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 65335
97
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Exactly. What advantage could the added complexity possibly afford?
 
Reidar Gjerstad
Greenhorn
Posts: 19
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
OK. Thanks for clarifying.

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.

It makes sense.

Cheers
 
Petar Thomas
Ranch Hand
Posts: 234
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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".




So:

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

example:



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.
 
Devaka Cooray
Marshal
Pie
Posts: 4879
402
Chrome Eclipse IDE Google App Engine IntelliJ IDE jQuery Postgres Database Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Petar Thomas
Ranch Hand
Posts: 234
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
That's absolutely true. : )

But Tetris could extend HttpServletResponseWrapper
 
Devaka Cooray
Marshal
Pie
Posts: 4879
402
Chrome Eclipse IDE Google App Engine IntelliJ IDE jQuery Postgres Database Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Petar Tomičić wrote:But Tetris could extend HttpServletResponseWrapper

Yep
 
Petar Thomas
Ranch Hand
Posts: 234
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic