htmlParser在设置cookies时存在bug,对于相同的domain,不能设置多个cookies.下面时偶提交的bug内容及解决办法.偶英语很烂--大家别笑话.:P
There can't set many cookies to a domain,for example:
{
StringurlString
= " http://sourceforge.net/projects/htmlparser " ;
Parserparser = this .buildParser(urlString);


}
private ParserbuildParser(StringurlString) throws
Exception
{
ConnectionManagermanager =
Parser.getConnectionManager();
Cookiecookie = new Cookie( " name1 " , " value1 " );
manager.setCookie(cookie, " sourceforge.net " );
cookie = new Cookie( " name2 " , " value2 " );
manager.setCookie(cookie, " sourceforge.net " );
return new Parser(urlString);
}
only the first cookie was set to the
domain "sourceforge.net".
This bug comes with the
method:ConnectionManager.setCookie (Cookie cookie,
String domain),there can't add a new cookie to a exist
domain.
It is ok if repleace the method with under codes :
public
void
setCookie(Cookiecookie,Stringdomain)
{
Stringpath;
Vectorcookies;
Cookieprobe;
if
(
null
!=
cookie.getDomain())
domain
=
cookie.getDomain();
path
=
cookie.getPath();
if
(
null
==
mCookieJar)
mCookieJar
=
new
Hashtable();
//
turnon
cookieprocessing
cookies
=
(Vector)mCookieJar.get(domain);
if
(
null
!=
cookies)
{
boolean
isNewCookie
=
true
;
for
(
int
j
=
0
;j
<
cookies.size();j
++
)
{
probe
=
(Cookie)cookies.elementAt(j);
if
(probe.getName().equalsIgnoreCase
(cookie.getName()))
{
if
(isNewCookie
==
true
)isNewCookie
=
false
;
//
wekeeppathssortedmostspecificto
least
if
(probe.getPath().equals(path))
{
cookies.setElementAt(cookie,j);
//
replace
break
;
}
else
if
(path.startsWith(probe.getPath()))
{
cookies.insertElementAt(cookie,j);
break
;
}
}
}
if
(isNewCookie
==
true
)
{
cookies.addElement(cookie);
}
}
else
{
//
newcookielistneeded
cookies
=
new
Vector();
cookies.addElement(cookie);
mCookieJar.put(domain,cookies);
}
}