aspose file tools*
The moose likes Web Component Certification (SCWCD/OCPJWCD) and the fly likes Why isn't there a Response scope? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Certification » Web Component Certification (SCWCD/OCPJWCD)
Bookmark "Why isn Watch "Why isn New topic
Author

Why isn't there a Response scope?

Reidar Gjerstad
Greenhorn

Joined: Dec 02, 2008
Posts: 19
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
ExamLab Creator
Saloon Keeper

Joined: Jul 29, 2008
Posts: 3220
    
  49

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.


Author of ExamLab ExamLab - a free SCJP / OCPJP exam simulator
What would SCJP exam questions look like? -- Home -- Twitter -- How to Ask a Question
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61657
    
  67

Exactly. What advantage could the added complexity possibly afford?


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
Reidar Gjerstad
Greenhorn

Joined: Dec 02, 2008
Posts: 19
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

Joined: Oct 11, 2009
Posts: 234
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
ExamLab Creator
Saloon Keeper

Joined: Jul 29, 2008
Posts: 3220
    
  49

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

Joined: Oct 11, 2009
Posts: 234
That's absolutely true. : )

But Tetris could extend HttpServletResponseWrapper
Devaka Cooray
ExamLab Creator
Saloon Keeper

Joined: Jul 29, 2008
Posts: 3220
    
  49

Petar Tomičić wrote:But Tetris could extend HttpServletResponseWrapper

Yep
Petar Thomas
Ranch Hand

Joined: Oct 11, 2009
Posts: 234
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Why isn't there a Response scope?