package com.roshka.webprojecttest.servlets; 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("/tabla-multiplicar") public class TablaMultiplicarServelet extends HttpServlet { protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException { PrintWriter pw = new PrintWriter(resp.getOutputStream()); Boolean valido=true; String parametro = req.getParameter("number"); if(parametro == null) { initForm(pw); }else { if(parametro.length() <1) valido=false; for(int i = 0 ; i < parametro.length(); i++) { if( ( !Character.isDigit(parametro.charAt(i)) && i > 0) && !(Character.isDigit(parametro.charAt(i)) && i == 0 && parametro.charAt(i) != '-' ) ) { valido=false; break; } } if (!valido) { invalid(pw, parametro); } else { Integer numero = Integer.parseInt(parametro); if(numero > 100) { greaterThan100(pw, numero); } else if(numero<0) { negative(pw); } else{ theTable(pw, numero); } } } pw.close(); } void initForm(PrintWriter pw) { pw.write("" + "
" + ""+numero+" | " + "* | "+ "1 | " +"= | " + ""+(numero*1) + " | " + "
---|---|---|---|---|
"+numero+" | " + "* | "+ "2 | " +"= | " + ""+(numero*2) + " | " + "
"+numero+" | " + "* | "+ "3 | " +"= | " + ""+(numero*3) + " | " + "
"+numero+" | " + "* | "+ "4 | " +"= | " + ""+(numero*4) + " | " + "
"+numero+" | " + "* | "+ "5 | " +"= | " + ""+(numero*5) + " | " + "
"+numero+" | " + "* | "+ "6 | " +"= | " + ""+(numero*6) + " | " + "
"+numero+" | " + "* | "+ "7 | " +"= | " + ""+(numero*7) + " | " + "
"+numero+" | " + "* | "+ "8 | " +"= | " + ""+(numero*8) + " | " + "
"+numero+" | " + "* | "+ "9 | " +"= | " + ""+(numero*9) + " | " + "
"+numero+" | " + "* | "+ "10 | " +"= | " + ""+(numero*10)+ " | " + "