Hi,
Had tried your code, and it is giving NullPointerException, when you are
trying to get the name of the cookies because your cookies == null.
Try this code:
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("*************: " + cookies);
String cookieName = "MyCookie";
String cookieValue = "MyValue";
if (cookies == null){
Cookie cookie = new Cookie(cookieName, cookieValue);
response.addCookie(cookie);
System.out.println("cookies set");
System.out.println("(4) The first cookie in the array is: "
+ cookie.getName());
}
else{
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() {
}
}
Regards,
Vikramjit Singh,
GTL Ltd.
Ph. 7612929-1059
___________________________________________________________________________
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