Código:
<html> <head> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"> <title>JSP Page</title> </head> <body> <form method="post" action="index.jsp"> <select name="numero"> <% int x=0; for(x=2; x<11; x++) { if (request.getParameter("numero") != null)) && Integer.parseInt(Integer.parseInt(request.getParameter("numero"))==x) { out.println ("<option selected>x</option>"); } else { out.println ("<option>x</option>"); } } %> </select> <input type="submit" value="Enviar" name="enviar"> </form> <% int i=0; if(request.getParameter("numero")) { out.println ("<form method='post' action='index.jsp?numero="+request.getParameter("numero")+"'> "); for(i=0;i<Integer.parseInt(request.getParameter("numero"));i++) { if(Integer.parseInt(request.getParameter["caixa"][i])) { out.println ("<input type='text' value='"+request.getParameter("numero")[i]+"' name='caixa[]'><br>"); } else { out.println ("<input type='text' name='caixa[]'><br>"); } } out.println ("<input type='submit' value='Sumar' name='sumar'>"); out.println ("</form> "); } if(request.getParameter["caixa"]) { int suma=0; foreach(request.getParameter["caixa"] as $valor) suma = suma + $valor; out.println ("<br>La suma dels números és: "+suma); } %> </body> </html>