1 import java.io.*; 2 import java.util.ArrayList; 3 4 import javax.servlet.*; 5 import javax.servlet.http.*; 6 7 import jodd.servlet.*; 8 9 10 public class PrimesAction extends ActionServlet { 11 12 15 public String doAction(HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException { 16 String maxNum = request.getParameter("max"); 17 int max = Integer.parseInt(maxNum); 18 ArrayList al = new ArrayList(); 19 for (int i = 1; i < max; i++) { 20 System.out.println(i); 21 boolean isPrime = true; 22 for (int j = 2; j < i; j++) { 23 if (i % j == 0) { 24 isPrime = false; 25 break; 26 } 27 } 28 if (isPrime == true) { 29 al.add(new Integer(i)); 30 } 31 } 32 request.setAttribute("primes", al); 33 return "ok"; 34 } 35 } 36 37 | Popular Tags |