calling request.getHEades("user-agent") twice ->NPE?!
- From: Stefanie Ertheld <Stefanie.Erteld@xxxxxxx>
- Date: Thu, 31 Jan 2008 08:39:26 +0100
Hi,
I got the following line of code:
if (request.getHeaders("user-agent") != null && request.getHeaders("user-agent").nextElement() != null)
Which throws a NullPointerException at .nextElement().
(I know I could improve the code but thats not the point here)
The api for getHeaders says:
<API>
getHeaders
public java.util.Enumeration getHeaders(java.lang.String name)
Returns all the values of the specified request header as an Enumeration of String objects.
Some headers, such as Accept-Language can be sent by clients as several headers each with a different value rather than sending the header as a comma separated list.
If the request did not include any headers of the specified name, this method returns an empty Enumeration. The header name is case insensitive. You can use this method with any request header.
Parameters:
name - a String specifying the header name
Returns:
an Enumeration containing the values of the requested header. If the request does not have any headers of that name return an empty enumeration. If the container does not allow access to header information, return null
</API>
So the important part is probably:
1. If the request did not include any headers of the specified name, this method returns an empty Enumeration.
2. If the container does not allow access to header information, return null
------
But I don't get why requesting the same header info twice would not be allowed?!
Any ideas?
Thanks in advance,
Stefanie
.
- Follow-Ups:
- Re: calling request.getHEades("user-agent") twice ->NPE?!
- From: GArlington
- Re: calling request.getHEades("user-agent") twice ->NPE?!
- Prev by Date: Re: Closing ServletInputStream
- Next by Date: Re: Updating documents in Lucene
- Previous by thread: J2ee chief Software Engineers job opening with Worlds Largest Company, Bangalore
- Next by thread: Re: calling request.getHEades("user-agent") twice ->NPE?!
- Index(es):
Relevant Pages
|