<%@ page language="java" pageEncoding="GBK"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title>prime numbers</title>
</head>
<%!
public boolean isPrime(int n) {
for (int i=2; i<n; i++) {
if(n%i==0)
return false;
}
return true;
}
%>
<%
int num = 0;
String str = request.getParameter("num");
if (str!=null)
num = Integer.parseInt(str);
%>
<body>
<form action="#" method="post">
<input type="text" name="num">
<input type="submit" value="submit">
</form>
<br>
<%
if(num!=0) {
for (int i=2; i<num; i++) {
if(isPrime(i)) {
out.print(i+" ");
}
}
}
%>
</body>
</html>