Java 中错误 : Null

时间:2024-10-10 07:39:41
import java.io.IOException; import java.io.PrintWriter; import javax.servlet.ServletException; import javax.servlet.annotation.WebServlet; import javax.servlet.http.HttpServlet; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; @WebServlet("/ExampleMath")ExampleMath public class ExampleMath extends HttpServlet { private static final long serialVersionUID = 1L; protected void doPost(HttpServletRequest HTTP_Request, HttpServletResponse HTTP_Response) throws ServletException, IOException,NumberFormatException { HTTP_Response.setContentType("text/html"); PrintWriter Print_Writer = HTTP_Response.getWriter(); int Number1 = Integer.parseInt(HTTP_Request.getParameter("first")); int Number2 = Integer.parseInt(HTTP_Request.getParameter("second")); String Symbol = HTTP_Request.getParameter("math"); int result = 0; if(Symbol.equals("addition")) result = Number1 + Number2; else if(Symbol.equals("substraction")) result = Number1 - Number2; else if(Symbol.equals("multiplication")) result = Number1 * Number2; else result = Number1 / Number2; Print_Writer.println(result); } }