Solved

Cookie method error

Posted on 2004-09-16
8
224 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
Technology Partners: 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

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone 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

Suggested Solutions

Digital services have impacted the providers of three major areas: revenue generation, enhanced customer experience, and cost optimization. An increase in revenue generation through the use of modern upsells whilst giving digital services to the cus…
Australian government abolished Visa 457 earlier this April and this article describes how this decision might affect Australian IT scene and IT experts.
I've attached the XLSM Excel spreadsheet I used in the video and also text files containing the macros used below. https://filedb.experts-exchange.com/incoming/2017/03_w12/1151775/Permutations.txt https://filedb.experts-exchange.com/incoming/201…
Suggested Courses

740 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