tomcat-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Paul Yunusov <pyunu...@rogers.com>
Subject Re: interesting java.lang.NullPointerException error when first viewing an index.jsp page - refresh once and page loads correctly
Date Sat, 11 Jan 2003 14:52:48 GMT
On Friday 10 January 2003 05:49 pm, Brandon Rodak wrote:
> Paul,
>
> Here is a link to the Java - http://www.flex-internet.com/java.txt
>
> Thanks again for your help
>
> Brandon Rodak
> Web Services
> Computer Marketing Corporation
> http://www.cmcflex.com & http://www.flex-internet.com

Brandon, the scriptlet in your jsp gets your server's cookies from the client:

Cookie[] cookies = request.getCookies();

but on the initial request, there are no cookies set by your server on any 
given client, so getCookies() returns null in accordance with the servlet 
spec. That triggers a NPE when you try to process the cookies later:

for (int i=0; i<cookies.length; i++) {
...
}

Put an "if" statement around your "for" loop to check if cookies is null or 
not and that should fix your problem.


Paul

--
To unsubscribe, e-mail:   <mailto:tomcat-user-unsubscribe@jakarta.apache.org>
For additional commands, e-mail: <mailto:tomcat-user-help@jakarta.apache.org>


Mime
View raw message