有异常,求解决

来源:2-5 保存上传文件内容

qq_柒分醉_03927370

2017-05-15 10:44

五月 15, 2017 10:38:46 上午 org.apache.catalina.core.StandardWrapperValve invoke

严重: Servlet.service() for servlet [UploadServlet] in context with path [/scxz] threw exception

java.lang.StringIndexOutOfBoundsException: String index out of range: -1

at java.lang.String.substring(Unknown Source)

at com.imooc.servlet.UploadServlet.doPost(UploadServlet.java:46)

at javax.servlet.http.HttpServlet.service(HttpServlet.java:646)

at javax.servlet.http.HttpServlet.service(HttpServlet.java:727)

at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:303)

at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208)

at org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)

at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:241)

at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208)

at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:220)

at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:122)

at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:501)

at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:170)

at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:98)

at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:950)

at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:116)

at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:408)

at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1040)

at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:607)

at org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:313)

at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)

at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)

at java.lang.Thread.run(Unknown Source)


写回答 关注

1回答

  • qq_莫非
    2017-05-15 13:07:12

    需要有个地方设置 request.setAttribute("vector" , vector对象);
    然后才能取值,一般是在 session 中 setAttribute 和 getAttribute.
    request.getAttribute("vector"); 没有取到 vector  值,  
    可以改成 if(  request.getAttribute("vector") != null) {
                              vector = (Vector) request.getAttribute("vector");

                                  Vector news = (Vector) vector.get(0);
    Vector hot = (Vector) vector.get(1);
    Vector placard = (Vector) vector.get(2);

     }

Java中的文件上传下载

由简入深,轻松实现文件上传下载功能及相关框架的使用

77391 学习 · 337 问题

查看课程

相似问题