Solved

Cookie method error

Posted on 2004-09-16
8
212 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
  • 3
  • 3
8 Comments
 
LVL 32

Accepted Solution

by:
ldbkutty earned 300 total points
Comment Utility
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
Comment Utility
I do :(
0
 
LVL 19

Assisted Solution

by:ramazanyich
ramazanyich earned 200 total points
Comment Utility
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
Find Ransomware Secrets With All-Source Analysis

Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

 
LVL 2

Author Comment

by:k41d3n
Comment Utility
Excellent, thank you.

0
 
LVL 32

Expert Comment

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

?
0
 
LVL 2

Author Comment

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

Expert Comment

by:ldbkutty
Comment Utility
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

What Should I Do With This Threat Intelligence?

Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

Join & Write a Comment

Suggested Solutions

Possible fixes for Windows 7 and Windows Server 2008 updating problem. Solutions mentioned are from Microsoft themselves. I started a case with them from our Microsoft Silver Partner option to open a case and get direct support from Microsoft. If s…
In this step by step tutorial with screenshots, we will show you HOW TO: Enable SSH Remote Access on a VMware vSphere Hypervisor 6.5 (ESXi 6.5). This is important if you need to enable SSH remote access for additional troubleshooting of the ESXi hos…
Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.
In this tutorial you'll learn about bandwidth monitoring with flows and packet sniffing with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're interested in additional methods for monitoring bandwidt…

762 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

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now