try {
Integer.parseInt(req.getParameter(OPERAND_ONE));
} catch (NumberFormatException nfe) {
// in reality we would use a RequestDispatcher to forward
// to an error page.
throw new ServletException(nfe.getMessage());
}
try {
Integer.parseInt(req.getParameter(OPERAND_TWO));
} catch (NumberFormatException nfe) {
// in reality we would use a RequestDispatcher to forward
// to an error page.
throw new ServletException(nfe.getMessage());
}
String operator = req.getParameter(OPERATION);
if (!("+".equals(operator) || "-".equals(operator))) {
// in reality we would use a RequestDispatcher to forward
// to an error page.
throw new ServletException("Invalid Operator. " +
"[operator=" + operator + "]");
}