gpt4 book ai didi

java - jsp中提交类型错误

转载 作者:行者123 更新时间:2023-12-01 14:12:47 25 4
gpt4 key购买 nike

我在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]

我听不懂,请帮帮我

最佳答案

查看异常,我发现您正在执行的jsp中的某处

Long.parseLong(someStringVariable);

someStringVariablenull。因此,在解析为 Long

之前检查 null
if(someStringVariable != null) {
Long.parseLong(someStringVariable);
}

注意:

  • 即使 someStringVariable 不为 null,如果字符串不是可解析的格式,Long.parseLong(someStringVariable) 仍然可能会抛出异常
  • 建议使用JSTL in JSP并将所有解析逻辑留给Servlet

关于java - jsp中提交类型错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18372876/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com