Solved

How can I handle cookies?

Posted on 2003-11-20
1
306 Views
Last Modified: 2010-04-01
Hi all,

I want to save the member login information in Cookies. After user login, the information will be auto-add to client side PC, and show it in FORM next time. Once I put the GETCOOKIES statement, it generated error when enter the site said that: java.lang.NullPointerException.

But, when the user logined before, this error will not be show. I know that it is the error about the Cookie, but, how can I know the cookies has data or not before get it?

here is my code:

String cookiemail="";
Cookie cookies[]=request.getCookies();

for (int i=0;i<cookies.length;i++){
if(cookies[i].getName().equals("cookiemail")){
cookiemail=cookies[i].getValue();
break;
}
}

please help. Thanks!
0
Comment
Question by:efkw
1 Comment
 
LVL 2

Accepted Solution

by:
DidierD earned 65 total points
ID: 9795410
Try this

String cookiemail="";
Cookie cookies[]=request.getCookies();

if (cookies != null){
  for (int i=0;i<cookies.length;i++){
    if("cookiemail".equals(cookies[i].getName()){
      cookiemail=cookies[i].getValue();
      break;
    }
  }
}
0

Featured Post

Enabling OSINT in Activity Based Intelligence

Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

Join & Write a Comment

In this article, I will show you HOW TO: Install VMware Tools for Windows on a VMware Windows virtual machine on a VMware vSphere Hypervisor 6.5 (ESXi 6.5) Host Server, using the VMware Host Client. The virtual machine has Windows Server 2016 instal…
Find out what the Office 365 disclaimer function is, why you would use it and its limited ability to create Office 365 signatures.
It is a freely distributed piece of software for such tasks as photo retouching, image composition and image authoring. It works on many operating systems, in many languages.
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…

744 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now