user.add(username);
request.getRequestDispatcher("/add_success.jsp").forward(request, response);
String requestURI = request.getRequestURI();
String path = requestURI.substring(requestURI.indexOf("/", 1), requestURI.indexOf(".")); //这行有错!
System.out.println("path=" + path);
type Exception report
message
description The server encountered an internal error () that prevented it from fulfilling this request.
exception
java.lang.StringIndexOutOfBoundsException: String index out of range: -11
java.lang.String.substring(String.java:1938)
com.TestTest.TestServlet.doPost(TestServlet.java:27)
javax.servlet.http.HttpServlet.service(HttpServlet.java:637)
javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
note The full stack trace of the root cause is available in the Apache Tomcat/6.0.33 logs.
------解决方案--------------------
你是想截取/ 到. 之间的字符串吧。如果是这样就应该这样用
String path = requestURI.substring(requestURI.indexOf("/", 1), requestURI.indexOf(".")-requestURI.indexOf("/", 1),);
这样就对了
代码迷推荐解决方案:The server encountered an internal error () that prevented it from fulfilling this request.,http://www.daimami.com/search?q=317