Posted on 2005-04-24
Medium Priority
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

ID: 13853037

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

ID: 13853127
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

TimYates earned 2000 total points
ID: 13853234
   for (int i =0; i< cookies.length; i++) {

should be

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

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

I am posting this in case anyone runs into similar issues that I did, this may save you a lot of grief: Condition: 1. Your NetBIOS domain name contains an ampersand " & " character.  (e.g. AT&T) 2. You've tried to run any Microsoft installation…
The following information will get you familiar with your new DV server, including the (mt) Account Center, the Plesk Control Panel, our world-renowned support department and the rest of the (mt) tools that come with your new service.
How can you see what you are working on when you want to see it while you to save a copy? Add a "Save As" icon to the Quick Access Toolbar, or QAT. That way, when you save a copy of a query, form, report, or other object you are modifying, you…
Stellar Phoenix SQL Database Repair software easily fixes the suspect mode issue of SQL Server database. It is a simple process to bring the database from suspect mode to normal mode. Check out the video and fix the SQL database suspect mode problem.
Suggested Courses

621 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