换句话说,我无法更新数字,如果第一个数字是 8 和 13,并且有人提交了 21,那么下次有人加载页面时,数字将是 13 和 21。我知道我的会话有问题,但不要不知道什么
<%@ page import="java.io.*"%><%@
import="java.util.*"%><?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html;charset=utf-8" />
<title>MAIN</title>
</head>
<body>
<%
String sum = (String) session.getAttribute("sum");
if (sum==null) {
sum = "0";
session.setAttribute("sum",sum);
}
int isum = Integer.parseInt(sum);
String fib1= (String) session.getAttribute("fib1");
fib1 = "8";
session.setAttribute("fib1",fib1);
int ifib1 = Integer.parseInt(fib1);
String fib2= (String) session.getAttribute("fib2");
fib2 = "13";
int ifib2 = Integer.parseInt(fib2);
isum=ifib1+ifib2;
boolean numberReceived=false;
int usum = -1;
try{
usum=Integer.parseInt(request.getParameter("number"));
numberReceived=true;
}catch(NumberFormatException nfe){
System.out.print("error");
}
if (!numberReceived) {
out.print("You need to enter a value");
} else {
if (usum==isum) {
out.print("correct");
ifib1+=5;
} else {
out.print("incorrect");
}
}
session.setAttribute("fib1",""+ifib1);
%>
<input type="button" value="go" onclick="doTheGObutton();">
<form action="index.jsp" method="post">
<%=fib1%> + <%=fib2%> = <input type="text" name="number">
<input type="submit" value="continue" name="submit">
</form>
</body>
</html>