aspose file tools
The moose likes Web Component Certification (SCWCD/OCPJWCD) and the fly likes getIntHeader method Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login


Win a copy of The Mikado Method this week in the Agile and other Processes forum!
JavaRanch » Java Forums » Certification » Web Component Certification (SCWCD/OCPJWCD)
Reply Bookmark "getIntHeader method" Watch "getIntHeader method" New topic
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:

 
I agree. Here's the link: http://zeroturnaround.com/jrebel - it saves me about five hours per week
 
subject: getIntHeader method
 
Similar Threads
pageContext implicit object
Reading int headers from a Servlet
Getting and sending Header information, help needed
How to set http headers in servlet request ?
Doubt in setHeader Method