gpt4 book ai didi

java.lang.NumberFormatException : For input string: "firstno" 异常

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

<分区>

我正在尝试运行一个程序。我真的是 java 新手。当我运行我的程序时,出现以下异常。

type Exception report
message For input string: "firstno"

description The server encountered an internal error that prevented it from fulfilling his request.
exception

java.lang.NumberFormatException: For input string: "firstno"
java.lang.NumberFormatException.forInputString(NumberFormatException.java:65)
java.lang.Integer.parseInt(Integer.java:492)
java.lang.Integer.parseInt(Integer.java:527)
MathEx.doPost(MathEx.java:34)
javax.servlet.http.HttpServlet.service(HttpServlet.java:647)
javax.servlet.http.HttpServlet.service(HttpServlet.java:728)

这是我的代码供您引用。

import java.sql.*;
import java.io.*;
import javax.servlet.*;
import javax.servlet.http.*;

public class MathEx extends HttpServlet
{
public void doGet(HttpServletRequest p, HttpServletResponse q) throws ServletException, IOException
{
q.setContentType("Text/HTML");
PrintWriter out = q.getWriter();

out.println("<form method=post>");
out.println("Enter first number");
out.println("<input type=text name=first>");
out.println("<br><br>");
out.println("Enter second no.");
out.println("<input type=text name=second>");
out.println("<br><br>");
out.println("<input type=submit name=send value=ADDITION>");
out.println("<input type=submit name=send value=SUBSTRACTION>");

out.println("<input type=submit name=send value=END>");
out.println("</form>");
}

public void doPost(HttpServletRequest s, HttpServletResponse t) throws ServletException, IOException
{
t.setContentType("TEXT/HTML");
PrintWriter out=t.getWriter();
String firstno = s.getParameter("first");
String secondno = s.getParameter("Second");
String choice = s.getParameter("send");
int fno=Integer.parseInt("firstno");
int sno=Integer.parseInt("secondno");
int result;
out.println("First no ="+fno);
out.println("<br><br>");
out.println("Second no ="+sno);
out.println("<br><br>");

if (choice.equals("ADDITION"))
{
result=fno+sno;
out.println("The result of addition= "+result);
}


if (choice.equals("SUBSTRACTION"))
{
result=fno-sno;
out.println("The result of substraction= "+result);
}


if (choice.equals("END"))
{
out.println("Thank you have a nice day");
return;
}


out.println("<br><br><br>");
doGet(s,t);
{
out.println("<br><br><br>");
out.println("bye bye");
}

}

}

我真的不明白为什么会这样。请给我任何引用或提示。

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