#对于是质数的定义可以去百度百科或者谷歌说明很清楚.这里就不细说.
后台的代码
@RequestMapping(value = “/json”, method = RequestMethod.GET)
`@ResponseBody
public String getAjax(@RequestParam(value = "minimum", required = false) Integer minimum, @RequestParam(value = "maximum") Integer maximum) {
Integer num = null;
StringBuffer sb = new StringBuffer();
boolean falg;
for (int i = minimum; i <= maximum; i++) {
//首先的过滤掉是1 和偶数
if (i == 1 || (i % 2 == 0 && i != 2)) {
continue;
}
falg = true;
//这个是过滤后的数据再来遍历判断它是否还要可拆分的因子,如果没有说明是质数
for (int j = 2; j < i; j++) {
if (i % j == 0) {
falg = false;
break;
}
}
if (falg) {
num = i;
sb.append(num.toString());
sb.append("\t");
}
}
return sb.toString();//返回个前台,通过ajax 获取.
}`
<--------------------------------------`-------------前台显示的代码--------------------------------------------------->
<SCRIPT>
$("FORM").submit(function CheckPost() {
var minimum = $("#minimum").val();//获取输入值
var maximum = $("#maximum").val();
$.ajax({
type: "get",
url: "json",
data: {"minimum": minimum, "maximum": maximum},//json数据格式
contentType:"application/json;charset=UTF-8",
success: function (data) {
$("#text").text(data );//获取控件 并把数据写入进去
}
});
});
</SCRIPT>
</BODY>