Posted on 2005-04-24
Last Modified: 2010-04-01
Dear all,

I put this in util file (to retrive cookies) :

<%@ page import="javax.servlet.http.Cookie" %>
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;

I got this error:
request cannot be resolved
Also I got this error :
cookies.length cannot be resolved or is not a type
Question by:ethar1
    LVL 16

    Expert Comment


    If you put this class in util, how do you expect the method to know what request is? Normally, if you put it in your servlet or etc, you will be able to get the request by HttpServletRequest. So on my opinion is that, you need to put this in your Servlet.


    Author Comment

    k, I pass the request to the function , but still got this error:
    cookies.length cannot be resolved or is not a type
    LVL 35

    Accepted Solution

       for (int i =0; i< cookies.length; i++) {

    should be

        for (int i =0; i< theCookies.length; i++) {

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    Why You Should Analyze Threat Actor TTPs

    After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

    Suggested Solutions

    Outlook Free & Paid Tools
    The recent Microsoft changes on update philosophy for Windows pre-10 and their impact on existing WSUS implementations.
    To add imagery to an HTML email signature, you have two options available to you. You can either add a logo/image by embedding it directly into the signature or hosting it externally and linking to it. The vast majority of email clients display l…
    Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…

    759 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

    10 Experts available now in Live!

    Get 1:1 Help Now