我正在尝试运行一个程序。我真的是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");
}
}
}
我真的不明白为什么会发生这种情况..请给我任何参考或提示。