Solved

How can I handle cookies?

Posted on 2003-11-20
1
312 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

The conference as a whole was very interesting, although if one has to make a choice between this one and some others, you may want to check out the others.  This conference is aimed mainly at government agencies.  So it addresses the various compli…
Gain an elementary understanding of Blockchain technology.
In this video, viewers are given an introduction to using the Windows 10 Snipping Tool, how to quickly locate it when it's needed and also how make it always available with a single click of a mouse button, by pinning it to the Desktop Task Bar. Int…
Michael from AdRem Software outlines event notifications and Automatic Corrective Actions in network monitoring. Automatic Corrective Actions are scripts, which can automatically run upon discovery of a certain undesirable condition in your network.…

707 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