- From: Rajesh Joshi <rjoshi@arsin.com>
- Date: Thu, 19 Nov 1998 15:10:45 -0500 (EST)
- To: "'www-jigsaw@w3.org'" <www-jigsaw@w3.org>
Hi, I am trying to set cookie in response header & then read the same information in another servlet. Sample code for setting is : Cookie c = new Cookie("Test", "yes"); c.setDomain("."+req.getServerName()); System.out.println("Server Name: " + req.getServerName()); c.setMaxAge(100000); res.addCookie(c); When I try to read the same, in the following piece of code: Cookie cookies[] = null; boolean rv = false; String strValue = new String(); System.out.println("readCookies"); try{ try { cookies = req.getCookies(); System.out.println(cookies); } catch (NullPointerException e) { System.out.println("Cookie Servlet::ReadCookie failed"); return rv; } if(cookies != null){ for(int i=0; i < cookies.length; i++){ Cookie thisCookie = cookies[i]; System.out.println("Cookie Server : " +thisCookie.getDomain()); String strCookieInfo = thisCookie.getName(); System.out.println(strCookieInfo); if (strCookieInfo.equals("Test")) { strValue = thisCookie.getValue(); System.out.println("Cookie UID : " + strValue); rv = true; } The get the "Null pointer exception" with message "Cookie Servlet::ReadCookie failed." The cookie.txt shows no entry for the cookie. Regards, Rajesh Joshi Arsin Corporation.
Received on Tuesday, 24 November 1998 03:23:52 UTC