Solved

How can I handle cookies?

Posted on 2003-11-20
1
309 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

Complete VMware vSphere® ESX(i) & Hyper-V Backup

Capture your entire system, including the host, with patented disk imaging integrated with VMware VADP / Microsoft VSS and RCT. RTOs is as low as 15 seconds with Acronis Active Restore™. You can enjoy unlimited P2V/V2V migrations from any source (even from a different hypervisor)

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
java.util.concurrent.Callable way of creating threads 2 106
Lamba in java 8 9 244
Struts tiles for layout structure along with Angular JS. 4 166
jdbc error in jsp application 20 48
There’s a good reason for why it’s called a homepage – it closely resembles that of a physical house and the only real difference is that it’s online. Your website’s homepage is where people come to visit you. It’s the family room of your website wh…
Each year, investment in cloud platforms grows more than 20% (https://www.immun.io/hubfs/Immunio_2016/Content/Marketing/Cloud-Security-Report-2016.pdf?submissionGuid=a8d80a00-6fee-4b85-81db-a4e28f681762) as an increasing number of companies begin to…
A short tutorial showing how to set up an email signature in Outlook on the Web (previously known as OWA). For free email signatures designs, visit https://www.mail-signatures.com/articles/signature-templates/?sts=6651 If you want to manage em…

825 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