日期:2014-05-18  浏览次数:20727 次

Servlet获取相同name的checkbox值的问题
一般的做法是
String[]   reviewcheckbox   =   request.getParameterValues( "checkbox ");
这样的,我也是如此做的。
但是每次没有办法获得第一个checkbox的值。
for   (int   i   =   0;   i   <   reviewcheckbox.length;   i++){
System.out.println(reviewcheckbox[i]);
}
第一个checkbox的值,没有打印出来。
WEB运行报错是
java.lang.ArrayIndexOutOfBoundsException:   3
at   servlet.eVoteServlet.doPost(eVoteServlet.java:28)
at   javax.servlet.http.HttpServlet.service(HttpServlet.java:763)
at   javax.servlet.http.HttpServlet.service(HttpServlet.java:856)
at   org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:284)
at   org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:204)
at   org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:257)
at   org.apache.catalina.core.StandardValveContext.invokeNext(StandardValveContext.java:151)
at   org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:567)
at   org.apache.catalina.core.StandardContextValve.invokeInternal(StandardContextValve.java:245)
at   org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:199)
at   org.apache.catalina.core.StandardValveContext.invokeNext(StandardValveContext.java:151)
at   org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:567)
at   org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:184)
at   org.apache.catalina.core.StandardValveContext.invokeNext(StandardValveContext.java:151)
at   org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:164)
at   org.apache.catalina.core.StandardValveContext.invokeNext(StandardValveContext.java:149)
at   org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:567)
at   org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:156)
at   org.apache.catalina.core.StandardValveContext.invokeNext(StandardValveContext.java:151)
at   org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:567)
at   org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:972)
at   org.apache.coyote.tomcat5.CoyoteAdapter.service(CoyoteAdapter.java:206)
at   org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:833)
at   org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.processConnection(Http11Protocol.java:732)
at   org.apache.tomcat.util.net.TcpWorkerThread.runIt(PoolTcpEndpoint.java:619)
at   org.apache.tomcat.util.threads.ThreadPool$ControlRunnable.run(ThreadPool.java:688)
at   java.lang.Thread.run(Unknown   Source)

谢谢

------解决方案--------------------
for (int i = 0; i < reviewcheckbox.length; i++){
System.out.println(reviewcheckbox[i]);
}

应该不会报那个数组越界的错误的