| Author |
getIntHeader method
|
Jose Esteban
Ranch Hand
Joined: Nov 28, 2004
Posts: 102
|
|
Hi, I have a question about the getIntHeader(String name) method in the HttpServletRequest interface. The specs say that "If the request does not have a header of the specified name, this method returns -1." My question is: how do you know, using only this method, if the header doesn't exist or if its value is -1? Thanks, Jose
|
 |
Jose Esteban
Ranch Hand
Joined: Nov 28, 2004
Posts: 102
|
|
Any answers? I think that if you use this method, you'd better be sure there's a head with the specified name, because if you get a -1 things could go wrong. Any comments? [ March 03, 2005: Message edited by: Jose Esteban ]
|
 |
Colin Fletcher
Ranch Hand
Joined: Sep 10, 2004
Posts: 200
|
|
I can think of two different ways I would handle that situation. How would you ensure that the int header you need to read is valid?
|
SCJP 1.4 SCWCD 1.4
|
 |
Jose Esteban
Ranch Hand
Joined: Nov 28, 2004
Posts: 102
|
|
Originally posted by Colin Fletcher: How would you ensure that the int header you need to read is valid?
I know that you could, for example, use getHeaderNames() and check if your header is in the Enumeration returned. But, does this mean that when you use getIntHeader(String name) you always need an aditional method to check if the header exists?
|
 |
Colin Fletcher
Ranch Hand
Joined: Sep 10, 2004
Posts: 200
|
|
I would, unless you know for 150% that the value will never be -1. An alternative:
|
 |
 |
|
|
subject: getIntHeader method
|
|
|