1つのプログラムを実行しようとしています。私は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");
}
}
}
なぜこれが起こったのか本当にわかりません..参考やヒントを教えてください。