Tomcat初始化期间的Java NumberFormatException

时间:2019-04-02 13:24:55

标签: tomcat server

当我尝试初始化Tomcat服务器时,出现错误:

HTTP状态500 –内部服务器错误

类型异常报告

消息java.lang.NumberFormatException:对于输入字符串:“ 0:0:0:0:0:0:0:0:1”

说明服务器遇到意外状况,阻止其满足请求。

例外

org.apache.jasper.JasperException:java.lang.NumberFormatException:对于输入字符串:“ 0:0:0:0:0:0:0:0:1”     org.apache.jasper.servlet.JspServletWrapper.handleJspException(JspServletWrapper.java:606)     org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:482)     org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:385)     org.apache.jasper.servlet.JspServlet.service(JspServlet.java:329)     javax.servlet.http.HttpServlet.service(HttpServlet.java:741)     org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:53) 根本原因

java.lang.NumberFormatException:对于输入字符串:“ 0:0:0:0:0:0:0:0:1”     java.base / java.lang.NumberFormatException.forInputString(NumberFormatException.java:68)     java.base / java.lang.Integer.parseInt(Integer.java:658)     java.base / java.lang.Integer.parseInt(Integer.java:776)     org.apache.jsp.index_jsp.validateInetAddress(index_jsp.java:466)     org.apache.jsp.index_jsp.ValidateIP(index_jsp.java:405)     org.apache.jsp.index_jsp._jspService(index_jsp.java:768)     org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70)     javax.servlet.http.HttpServlet.service(HttpServlet.java:741)     org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:444)     org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:385)     org.apache.jasper.servlet.JspServlet.service(JspServlet.java:329)     javax.servlet.http.HttpServlet.service(HttpServlet.java:741)     org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:53) 注意服务器日志中提供了根本原因的完整堆栈跟踪。

出什么问题了?如何解决?

1 个答案:

答案 0 :(得分:0)

您正在尝试将字符串强制转换为数字,而字符“:”不是数字。

您可以分割字符串并创建数字数组:

String string = "0:0:0:0:0:0:0:1";
String[] parts = string.split(":");
Int part1 = Integer.parseInt(parts[0]); // 0
Int part2 = Integer.parseInt(parts[1]); // 0
Int part3 = Integer.parseInt(parts[2]); // 0
Int part4 = Integer.parseInt(parts[3]); // 0
Int part5 = Integer.parseInt(parts[4]); // 0
Int part6 = Integer.parseInt(parts[5]); // 0
Int part7 = Integer.parseInt(parts[6]); // 0
Int part8 = Integer.parseInt(parts[7]); // 1

或循环

String string = "0:0:0:0:0:0:0:1";
String[] parts = string.split(":");
int[] nums = new int[parts.length];
for (int i = 0; i < parts.length-1; i++)
  nums[i] = Integer.parseInt(parts[i])