Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

curl -X GET http://localhost:8080/julian/resources/MyRestService/convert/222

GlassFish Server Open Source Edition 5.1.0 - Error report

HTTP Status 500 - Internal Server Error


type Exception report

messageInternal Server Error

descriptionThe server encountered an internal error that prevented it from fulfilling this request.

exception

javax.servlet.ServletException: java.lang.StringIndexOutOfBoundsException: String index out of range: 1

root cause

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

note The full stack traces of the exception and its root causes are available in the GlassFish Server Open Source Edition 5.1.0 logs.


GlassFish Server Open Source Edition 5.1.0

(base)
package book.jakarta.julian;

import javax.websocket.server.PathParam;
import javax.ws.rs.ApplicationPath;
import javax.ws.rs.GET;
import javax.ws.rs.Path;
import javax.ws.rs.Produces;
import javax.ws.rs.core.Application;
/**
 * 
 * Rest Web Service
 *
 */
@ApplicationPath("/resources")
@Path("MyRestService")
public class Julian  extends Application {
        
    // http://localhost:8080/julian/resources/MyRestService/convert/0123
    @GET
    @Produces("text/plain") 
    @Path("convert/{inNum : .*}")
            
    public String add(
            @PathParam("inNum") String inNum) {
        
          // get first digit ignore rest 
          int intemp = Integer.parseInt(inNum.substring(0, 1));
            
          return "" + (intemp + 3) ;
      }
}
question from:https://stackoverflow.com/questions/65890112/what-is-the-cause-of-java-lang-stringindexoutofboundsexception-string-index-out

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
1.5k views
Welcome To Ask or Share your Answers For Others

1 Answer

Waitting for answers

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...