For safety sake you should also check cookies.length > 0 before you
reference cookies[0].
  (*Chris*)

----- Original Message -----
From: "Siddharth" <[EMAIL PROTECTED]>
To: <[EMAIL PROTECTED]>
Sent: Tuesday, September 17, 2002 9:49 PM
Subject: Re: [SERVLET-INTEREST] Cookie help...


> Mike,
>
> Check if  var. "cookies" is null...
> and if is null then
> It must be throwing NullPointerException... so check your log.
>
> siddharth
>
> ----- Original Message -----
> From: Mike Cronin <[EMAIL PROTECTED]>
> To: <[EMAIL PROTECTED]>
> Sent: Wednesday, September 18, 2002 6:34 AM
> Subject: Cookie help...
>
>
> > Hi all,
> >
> > I am having a problem with cookies that has me a bit stumped.
> >
> > Processing appears to die as soon as I reference the array of cookies.
> >
> > In the following example, System.out.println (1) through (3) display
fine,
> > while System.out.println (4) and (5) do not. No errors are thrown,
> > processing
> > just stops.
> >
> > What am I missing?
> >
> > Thanks in advance!
> >
> > Mike Cronin
> >
> >
> > --------------------------------------------------------------
> > package doccookietest;
> >
> > import javax.servlet.*;
> > import javax.servlet.http.*;
> > import java.io.IOException;
> >
> > public class CookieServlet extends HttpServlet {
> >
> >   public void init(ServletConfig config) throws ServletException {
> >     super.init(config);
> >   }
> >
> >   public void doGet(HttpServletRequest request, HttpServletResponse
> > response) throws ServletException, IOException {
> >
> >     response.setContentType("text/html");
> >
> >     System.out.println("(1) In the CookieServlet doGet now!");
> >
> >     // Retrieve an array of cookies from the requesting browser
> >     Cookie[] cookies = request.getCookies();
> >
> >     System.out.println("(2) You have retrieved an array of cookies.");
> >
> >     System.out.println("(3) Prior to referencing the first element of
the
> > array...");
> >
> >     System.out.println("(4) The first cookie in the array is: " +
> > cookies[0].getName());
> >
> >     System.out.println("(5) Here is the first line after referencing the
> > array");
> >
> >   }
> >
> >   public void destroy() {
> >   }
> > }
> >
> > --------------------------------------------------------------
> >
> >
>
___________________________________________________________________________
> > To unsubscribe, send email to [EMAIL PROTECTED] and include in the
> body
> > of the message "signoff SERVLET-INTEREST".
> >
> > Archives: http://archives.java.sun.com/archives/servlet-interest.html
> > Resources: http://java.sun.com/products/servlet/external-resources.html
> > LISTSERV Help: http://www.lsoft.com/manuals/user/user.html
>
>
___________________________________________________________________________
> To unsubscribe, send email to [EMAIL PROTECTED] and include in the
body
> of the message "signoff SERVLET-INTEREST".
>
> Archives: http://archives.java.sun.com/archives/servlet-interest.html
> Resources: http://java.sun.com/products/servlet/external-resources.html
> LISTSERV Help: http://www.lsoft.com/manuals/user/user.html
>
>

___________________________________________________________________________
To unsubscribe, send email to [EMAIL PROTECTED] and include in the body
of the message "signoff SERVLET-INTEREST".

Archives: http://archives.java.sun.com/archives/servlet-interest.html
Resources: http://java.sun.com/products/servlet/external-resources.html
LISTSERV Help: http://www.lsoft.com/manuals/user/user.html

Reply via email to