Servlet.service() for servlet ConnectorServlet threw exception
java.lang.IndexOutOfBoundsException: Index: 0, Size: 0
at java.util.ArrayList.RangeCheck(ArrayList.java:547)
at java.util.ArrayList.get(ArrayList.java:322)
at net.fckeditor.connector.Dispatcher.doPost(Dispatcher.java:255)
at net.fckeditor.connector.ConnectorServlet.doPost(ConnectorServlet.java:128)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:710)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:803)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
at org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter.doFilter(StrutsPrepareAndExecuteFilter.java:88)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
at org.apache.struts2.dispatcher.FilterDispatcher.doFilter(FilterDispatcher.java:389)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:233)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:175)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:128)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:263)
at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:844)
at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:584)
at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:447)
at java.lang.Thread.run(Thread.java:619)
看了看大概是过滤器的问题。下面是原来的过滤器配置:
<filter>
<filter-name>struts2</filter-name>
<filter-class>org.apache.struts2.dispatcher.FilterDispatcher</filter-class>
</filter>
<filter-mapping>
<filter-name>struts2</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
还有一个StrutsPrepareAndExecuteFilter也是一样
解决方案一、
因此只要让过滤器不要处理fckeditor的那部分就好把<url-pattern>/*</url-pattern>改成
<servlet-name>action</servlet-name>就可以了
或者可以把需要由struts处理的归到某个特定的路径,比如/youSite/struts/*这样,然后把url-pattern改为youSite/struts/*;都可以目的是一样的。其实这里最简单的方法就是把不需要有struts过滤的页面直接排除掉,但是tomcat不支持这种方法(应该来说是servlet目前的规范还不支持,最新的应该是2.5吧)。但是有的servlet容器是支持的,比如Resin就支持这种情况,因为它的过滤功能中支持正则表示法(regular expression)。具体可以查看http://www.caucho.com/resin-3.0/config/webapp.xtp#filter-mapping
解决方案二、
FCKEditor是一个比较成熟的网页文本编辑器。根据官网提供的文档和demo很快就可以在自己的web服务中配置成功。但是由于集成在 struts2框架里,在上传图片时出现了问题,报错信息如下:
javax.servlet.ServletException: java.lang.IndexOutOfBoundsException: Index: 0, Size: 0
解决方案是,将web.xml中关于struts的filter-mapping设置为*.action,如果jsp中也使用到struts2的标签,则还要加上*.jsp。
<filter>
<filter-name>struts2</filter-name>
<filter-class>
org.apache.struts2.dispatcher.FilterDispatcher
</filter-class>
</filter>
解决方案三、
上传文件时后台报java.lang.IndexOutOfBoundsException: Index: 0, Size: 0错误,查找资料后发现是因与struts2的filter配置冲突所致,将web.xml中的struts配置修改后问题解决。
原配置:
struts2org.apache.struts2.dispatcher.FilterDispatcher