Solved

Cookie method error

Posted on 2004-09-16
8
225 Views
Last Modified: 2010-04-01
I got this method from an older jsp question:

public static String getCookieValue(String cookieName) {
     Cookie[] theCookies = request.getCookies();
     if (theCookies != null) {
        for (int i =0; i< cookies.length; i++) {
           Cookie currentCookie = theCookies[i];
           if (currentCookie.getName().equalsIgnoreCase(cookieName)
            return currentCookie.getValue();
           }
        }
   return null;
}

but when I try to use it, I get an error on the line:


     Cookie[] theCookies = request.getCookies();

that says package request does not exist.

Any ideas?

Thanks!
0
Comment
Question by:k41d3n
[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
  • 3
  • 3
8 Comments
 
LVL 32

Accepted Solution

by:
ldbkutty earned 300 total points
ID: 12078453
you should have import javax.servlet.http.*; and request defined, something like:

import javax.servlet.http.*;

public static String getCookieValue(String cookieName, HttpServletRequest request) {
    Cookie[] theCookies = request.getCookies();
    if (theCookies != null) {
        for (int i =0; i< theCookies.length; i++) {
            Cookie currentCookie = theCookies[i];
            if (currentCookie.getName().equalsIgnoreCase(cookieName))
                 return currentCookie.getValue();
            }
        }
    return null;
}
   
0
 
LVL 2

Author Comment

by:k41d3n
ID: 12078795
I do :(
0
 
LVL 19

Assisted Solution

by:ramazanyich
ramazanyich earned 200 total points
ID: 12079521
In your original method you access non-static variable request from static method.
So you should provide request as parameter for yur method:
public static String getCookieValue(String cookieName, HttpServletRequest request){
//...your code
}
0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 2

Author Comment

by:k41d3n
ID: 12079618
Excellent, thank you.

0
 
LVL 32

Expert Comment

by:ldbkutty
ID: 12082351
I dont understand..i showed the same in my code and explained it as "request defined"

?
0
 
LVL 2

Author Comment

by:k41d3n
ID: 12084618
You are absolutely correct, it's my fault I didn't read it properly.
0
 
LVL 32

Expert Comment

by:ldbkutty
ID: 12086564
Thanks for replying.

Please post here a Question and the moderators will re-open this Question:
http://www.experts-exchange.com/Community_Support/

:-)
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

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…
After seeing many questions for JRNL_WRAP_ERROR for replication failure, I thought it would be useful to write this article.
There are cases when e.g. an IT administrator wants to have full access and view into selected mailboxes on Exchange server, directly from his own email account in Outlook or Outlook Web Access. This proves useful when for example administrator want…
NetCrunch network monitor is a highly extensive platform for network monitoring and alert generation. In this video you'll see a live demo of NetCrunch with most notable features explained in a walk-through manner. You'll also get to know the philos…

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