这个网络应用程序是一个简单的加法和减法计算器。我的问题是加法和减法按钮不起作用。在我尝试使用 switch 语句之前,但现在我正在使用 if 语句但仍然不起作用
<%
String name = (String) session.getAttribute("name");
if (name==null) {
name = request.getParameter("name");
if (name!=null) session.setAttribute("name",name);
}
String sum = (String) session.getAttribute("sum");
if (sum==null) {
sum = "0";
session.setAttribute("sum",sum);
}
int isum = Integer.parseInt(sum);
String number = request.getParameter("number");
if (number==null) number = "0";
int inumber = Integer.parseInt(number);
if(request.getParameter("add") != null){
isum += inumber;
session.setAttribute("sum",""+isum);
}
if(request.getParameter("subtract") != null){
isum += inumber;
session.setAttribute("sum",""+isum);
}
%>
<html>
<head>
<title>Adding Machine</title>
</head>
<body>
<form method='get' action='adder.jsp'>
<%
if (name==null) {
%>
<p>
Name: <input type='text' name='name' id='name'>
</p>
<p>
<input type='submit' name='submit' id='submit' value='signin'>
</p>
<%
} else {
%>
<p>Welcome, <%=name%>!</p>
<p>Current sum is: <%=isum%></p>
<p>
Number to add: <input type='text' name='number' id='number' value='add'>
</p>
<p>
<input type='submit' name='submit' id='submit' value='add'>
</p>
<p>
<input type='submit' name='submit' id='submit' value='subtract'>
</p>
<%
}
%>
</form>
</body>
</html>