Win a copy of The Little Book of Impediments (e-book only) this week in the Agile and Other Processes forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

getIntHeader method

 
Jose Esteban
Ranch Hand
Posts: 102
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 102
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 200
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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?
 
Jose Esteban
Ranch Hand
Posts: 102
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 200
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I would, unless you know for 150% that the value will never be -1.

An alternative:

 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic