curl -X GET http://localhost:8080/julian/resources/MyRestService/convert/222
GlassFish Server Open Source Edition 5.1.0 - 错误报告HTTP 状态 500 - 内部服务器错误
类型异常报告
消息内部服务器错误
描述服务器遇到一个内部错误,阻止它完成这个请求。
例外
javax.servlet.ServletException:java.lang.StringIndexOutOfBoundsException:字符串索引超出范围:1
根本原因
java.lang.StringIndexOutOfBoundsException:字符串索引超出范围:1
note异常的完整堆栈跟踪及其根本原因可在 GlassFish Server Open Source Edition 5.1.0 日志中找到。
GlassFish Server 开源版 5.1.0
(根据)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) ;
}
}