?
Solved

cookies

Posted on 2005-04-24
3
Medium Priority
?
232 Views
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
Thanks.
0
Comment
Question by:ethar1
3 Comments
 
LVL 16

Expert Comment

by:suprapto45
ID: 13853037
Hi,

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.

Regards
Dave
0
 

Author Comment

by:ethar1
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
0
 
LVL 35

Accepted Solution

by:
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++) {
0

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