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 reportmessage 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.

解决方案 »

  1.   

    String path = requestURI.substring(requestURI.lastIndexOf("/", 1), requestURI.lastIndexOf(".")); 
    试试这样
      

  2.   

    String path = requestURI.substring(requestURI.indexOf("/", 0)+1,
    requestURI.indexOf(".")); 
    System.out.println("path=" + path);
      

  3.   

    你是想截取/   到. 之间的字符串吧。如果是这样就应该这样用
    String path = requestURI.substring(requestURI.indexOf("/", 1), requestURI.indexOf(".")-requestURI.indexOf("/", 1),);
    这样就对了