aspose file tools*
The moose likes Web Component Certification (SCWCD/OCPJWCD) and the fly likes Why ServletResponse doesn't have any attribute methods? 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 ServletResponse doesn Watch "Why ServletResponse doesn New topic
Author

Why ServletResponse doesn't have any attribute methods?

Faisal Ahmad
Ranch Hand

Joined: Aug 31, 2006
Posts: 355

Instead of adding attribute to the request object that's being passed to any 'view' from a servlet for e.g., it is better to add it to the response object - that sounds intuitive. It's like - servlet does something with the request (input) and passes on its results (output) through response object to the next item in action.

Looks weird? Please share your thoughts.
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 42292
    
  64
A response is generated once it's been determined how a request should be handled. So from that I find it more natural to attach attributes to requests, because the request will exist even when the response does not yet.

On a more practical level, I think it would be confusing to have attributes for both. By choosing one, it's clear where to look for attributes.


Ping & DNS - my free Android networking tools app
Faisal Ahmad
Ranch Hand

Joined: Aug 31, 2006
Posts: 355

Maneesh Godbole wrote:'Have' is correct English. Why do you want to change it to 'has'


I have some confusion regarding when to use 'doesn't have' and 'doesn't has'. I searched for some guidance on the web but I'm not fully convinced with the info that I found so far.
Faisal Ahmad
Ranch Hand

Joined: Aug 31, 2006
Posts: 355

Ulf Dittmer wrote:A response is generated once it's been determined how a request should be handled.


You mean - ServletResponse reference that is passed to a servlet doesn't refer to an existing object?


Ulf Dittmer wrote:So from that I find it more natural to attach attributes to requests, because the request will exist even when the response does not yet.

On a more practical level, I think it would be confusing to have attributes for both. By choosing one, it's clear where to look for attributes.


Consider the below flow:

Container passes client's request as an input to Servlet -> Servlet processes the input and adds its output/response to the ServletResponse object and then passes on these objects to next in action (view for e.g.) -> View checks the ServletResponse and performs some action based on the what it found.

It's Servlet's response. So, isn't it more intuitive/logical to find it in a 'ServletResponse' object?
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 42292
    
  64
ServletResponse reference that is passed to a servlet doesn't refer to an existing object?

No, the object is real. I meant the actual HTTP response.

Container passes client's request as an input to Servlet -> Servlet processes the input and adds its output/response to the ServletResponse object and then passes on these objects to next in action (view for e.g.) -> View checks the ServletResponse and performs some action based on the what it found.

It's Servlet's response. So, isn't it more intuitive/logical to find it in a 'ServletResponse' object?

I'd consider that a rather uncommon design. I wouldn't start assembling the response until I knew what exactly I'm about to assemble. That doesn't mean that response post-processing isn't useful at all (HTTP compression comes to mind), but if it needs additional information, then that information is determined by the request, not the response. Of course, what's intuitive to one person needn't be intuitive to some other person. But I do think it's better to attach attributes only to one of the objects, not to both, as I mentioned before.
Matthew Brown
Bartender

Joined: Apr 06, 2010
Posts: 4422
    
    8

Faisal Ahmad wrote:
Maneesh Godbole wrote:'Have' is correct English. Why do you want to change it to 'has'


I have some confusion regarding when to use 'doesn't have' and 'doesn't has'. I searched for some guidance on the web but I'm not fully convinced with the info that I found so far.


"Doesn't has" is always incorrect. It's a contraction of "... does not have", and in that case "does" is the verb that you're conjugating, and "have" is an infinitive. So "I do not have", "he does not have", "they do not have" etc.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Why ServletResponse doesn't have any attribute methods?