【发布时间】:2010-12-08 06:46:45
【问题描述】:
if (!foundCookie) {
logger.info("cooookies Not found --- ");
ResourceBundle appName = ResourceBundle.getBundle(
"conf/filename", Locale.getDefault());
Enumeration bundleKeys = appName.getKeys();
Cookie[] cookieToBeAdded = new Cookie[9000];
int i =0 ;
while (bundleKeys.hasMoreElements()) {
logger.error((String) bundleKeys.nextElement());
String key = (String) bundleKeys.nextElement();
String value = appName.getString(key);
cookieToBeAdded[i] = new Cookie(("station" + i),(key+":"+ value));
cookieToBeAdded[i].setMaxAge(24*60*60);
logger.error(cookieToBeAdded[i]+"cookieToBeAdded[i]");
// logger.info("cooookies adding to response --- " + cookieToBeAdded[i].getName() + ":" + cookieToBeAdded[i].getValue());
response.addCookie(cookieToBeAdded[i]);
pw.write("<Source>");
pw.write("<name>"+value+"</name>");
pw.write("<id>"+key+"</id>");
pw.write("</Source>");
i++;
}
}
我正在尝试运行上述代码,但出现以下错误:
java.lang.ArrayIndexOutOfBoundsException
at java.lang.System.arraycopy(Native Method)
at org.apache.coyote.http11.InternalOutputBuffer.write(InternalOutputBuffer.java:680)
at org.apache.coyote.http11.InternalOutputBuffer.sendStatus(InternalOutputBuffer.java:419)
at org.apache.coyote.http11.Http11Processor.prepareResponse(Http11Processor.java:1588)
at org.apache.coyote.http11.Http11Processor.action(Http11Processor.java:934)
at org.apache.coyote.Response.action(Response.java:183)
at org.apache.coyote.Response.sendHeaders(Response.java:379)
at org.apache.catalina.connector.OutputBuffer.doFlush(OutputBuffer.java:305)
at org.apache.catalina.connector.OutputBuffer.close(OutputBuffer.java:273)
at org.apache.catalina.connector.Response.finishResponse(Response.java:486)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:286)
at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:844)
at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:583)
at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:446)
at java.lang.Thread.run(Thread.java:636)
当我试图捕捉这个异常时,它并没有进入捕捉循环。 我正在向 cookie 添加大约 8999 个值。 cookie大小有限制吗?
我正在使用 JBoss,这是用 servlet(Java) 编写的。
请帮忙?
【问题讨论】:
-
您可能想为您的问题添加更多信息。这个错误究竟是什么时候发生的?您发布的代码似乎没有调用
arrayCopy,所以我认为错误来自其他地方。无论如何,Java 不会对 cookie 施加任何限制。 -
这让我很困惑。实际上,该 looger 行打印了 8973 次。之后它给出错误: java.lang.System.arraycopy(Native Method) 处的 java.lang.ArrayIndexOutOfBoundsException 这个错误堆栈跟踪甚至不包括我正在编写代码的类的名称。
-
你用的是什么版本的Tomcat?