1 <%@ page contentType="text/html; charset=UTF-8" pageEncoding="UTF-8" %> 2 <!DOCTYPE html> 3 <html> 4 <head> 5 <title>JSP - Hello World</title> 6 </head> 7 <body> 8 <h1><%= "Hello World!" %> 9 </h1> 10 <br/> 11 <% 12 int sum=0; 13 for(int i=1;i<=100;i++){ 14 if (i%2==0){ 15 sum=sum+i; 16 } 17 } 18 %> 19 偶数的总数为:<%=sum%> 20 <br/> 21 <% 22 int count = 0; 23 int j; 24 for (int i = 2; i <= 100; i++) { 25 for (j = 2; j < i; j++) { 26 if (i % j == 0) { 27 break; 28 } 29 } 30 if (j == i) { 31 count += i; 32 } 33 } 34 %> 35 素数的和为<%=count%> 36 </body> 37 </html>