编译错误???

ajzhn 2002-05-27 11:11:49
以下为源程序:

public class ServletUtilities {
public static final String DOCTYPE =
"<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.0 Transitional//EN\">";

public static String headWithTitle(String title) {
return(DOCTYPE + "\n" +
"<HTML>\n" +
"<HEAD><TITLE>" + title + "</TITLE></HEAD>\n");
}

//getCookieValue方法:获取指定名字的Cookie值
public static String getCookieValue( Cookie[] cookies,
String cookieName,
String defaultValue) {
for(int i=0; i<cookies.length; i++) {
Cookie cookie = cookies[i];
if (cookieName.equals(cookie.getName()))
return(cookie.getValue());
}
return(defaultValue);
}


// 其他工具函数的代码在本文后面介绍
}


在编译时会出现下列信息,是什么原因?求教 !!!

ServletUtilities.java:13: cannot resolve symbol
symbol : class Cookie
location: class ServletUtilities
public static String getCookieValue( Cookie[] cookies,
^
ServletUtilities.java:17: cannot resolve symbol
symbol : class Cookie
location: class ServletUtilities
Cookie cookie = cookies[i];
^
2 errors

...全文
7 点赞 收藏 2
写回复
2 条回复
切换为时间正序
当前发帖距今超过3年,不再开放新的回复
发表回复
Andrawu 2002-05-28
import javax.servlet.http.Cookie;
//增加Cookie包

public class ServletUtilities {
public static final String DOCTYPE =
"<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.0 Transitional//EN\">";

public static String headWithTitle(String title) {
return(DOCTYPE + "\n" +
"<HTML>\n" +
"<HEAD><TITLE>" + title + "</TITLE></HEAD>\n");
}

//getCookieValue方法:获取指定名字的Cookie值
public static String getCookieValue( Cookie[] cookies,
String cookieName,
String defaultValue) {
for(int i=0; i<cookies.length; i++) {
Cookie cookie = cookies[i];
if (cookieName.equals(cookie.getName()))
return(cookie.getValue());
}
return(defaultValue);
}


// 其他工具函数的代码在本文后面介绍
}
回复
liberty2000 2002-05-27
cookie是不是关键字?
回复
发动态
发帖子
Web 开发
创建于2007-09-28

7.9w+

社区成员

Java Web 开发
申请成为版主
社区公告
暂无公告