0

我在jsp上工作,我写了这段代码:

<form action="processInfo.jsp">
    <input type="submit" name="Kill" value="Kill" />
</form>
<%
    String s = request.getParameter("Kill");
    if (s != null) {
        System.out.println("ok");
    }
%>

但是这个错误已经出现了,我不知道为什么。

ERROR [org.apache.catalina.core.ContainerBase.[jboss.web].[default-host].[/SystemMonitoring_v1.2].[jsp]] (http--127.0.0.1-8080-1) Servlet.service() for servlet jsp threw exception: java.lang.NumberFormatException: null
at java.lang.Long.parseLong(Long.java:372) [rt.jar:1.6.0_13]
at java.lang.Long.parseLong(Long.java:461) [rt.jar:1.6.0_13]
at org.apache.jsp.processInfo_jsp._jspService(processInfo_jsp.java:64)
at org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70) [jbossweb-7.0.13.Final.jar:]
at javax.servlet.http.HttpServlet.service(HttpServlet.java:847) [jboss-servlet-api_3.0_spec-1.0.0.Final.jar:1.0.0.Final]
at org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:369) [jbossweb-7.0.13.Final.jar:]
at org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:326) [jbossweb-7.0.13.Final.jar:]
at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:253) [jbossweb-7.0.13.Final.jar:]
at javax.servlet.http.HttpServlet.service(HttpServlet.java:847) [jboss-servlet-api_3.0_spec-1.0.0.Final.jar:1.0.0.Final]
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:329) [jbossweb-7.0.13.Final.jar:]
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:248) [jbossweb-7.0.13.Final.jar:]
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:275) [jbossweb-7.0.13.Final.jar:]
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:161) [jbossweb-7.0.13.Final.jar:]
at org.jboss.as.web.security.SecurityContextAssociationValve.invoke(SecurityContextAssociationValve.java:153) [jboss-as-web-7.1.1.Final.jar:7.1.1.Final]
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:155) [jbossweb-7.0.13.Final.jar:]
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102) [jbossweb-7.0.13.Final.jar:]
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109) [jbossweb-7.0.13.Final.jar:]
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:368) [jbossweb-7.0.13.Final.jar:]
at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:877) [jbossweb-7.0.13.Final.jar:]
at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:671) [jbossweb-7.0.13.Final.jar:]
at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:930) [jbossweb-7.0.13.Final.jar:]
at java.lang.Thread.run(Thread.java:619) [rt.jar:1.6.0_13]

我看不懂,请你帮帮我

4

2 回答 2

1

看着exception, 我看到jsp你正在做的某处

Long.parseLong(someStringVariable);

并且someStringVariablenullnull所以在解析之前检查Long

if(someStringVariable != null) {
    Long.parseLong(someStringVariable);
}

笔记:

  • 即使someStringVariable不为空,Long.parseLong(someStringVariable)如果字符串不是可解析的格式,仍然可能抛出异常
  • 并且建议,在 JSP 中使用 JSTL,将所有的解析逻辑留给 Servlet
于 2013-08-22T06:19:53.763 回答
0

您正在尝试格式化 null。尝试检查它是否为空。

包括标签,

<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %>

并像这样格式化值,

<fmt:parseNumber var="i" type="number" value="${inputValue}" />
<p>Parsed Number : <c:out value="${i}" /></p>
于 2013-08-22T06:20:46.983 回答