Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Cookie method error

Posted on 2004-09-16
8
Medium Priority
?
228 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 1200 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 800 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
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 
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: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

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

If something goes wrong with Exchange, your IT resources are in trouble.All Exchange server migration processes are not designed to be identical and though migrating email from on-premises Exchange mailbox to Cloud’s Office 365 is relatively simple…
Article by: evilrix
Looking for a way to avoid searching through large data sets for data that doesn't exist? A Bloom Filter might be what you need. This data structure is a probabilistic filter that allows you to avoid unnecessary searches when you know the data defin…
This course is ideal for IT System Administrators working with VMware vSphere and its associated products in their company infrastructure. This course teaches you how to install and maintain this virtualization technology to store data, prevent vuln…
Are you ready to place your question in front of subject-matter experts for more timely responses? With the release of Priority Question, Premium Members, Team Accounts and Qualified Experts can now identify the emergent level of their issue, signal…

610 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