我正在尝试创建一个小程序,将两个数字作为用户通过miniadd.jsp的输入,将它们相加,然后在同一页上返回。我不得不在jsp中使用javabean。我不太确定我做了什么。但是现在我正在运行代码,我得到了[http status 500–internal server error]。org.apache.jasper.jasperexception:处理时发生异常。
有人能帮我解决哪里出了问题,我需要做什么吗?这是我目前的密码。
sumbeans2.java文件
package add;
import java.io.Serializable;
public class SumBean2 implements Serializable {
private int num1;
private int num2;
private int sum;
public SumBean2(){
}
public int getNum1() {
return num1;
}
public void setNum1(int num1) {
this.num1 = num1;
}
public int getNum2() {
return num2;
}
public void setNum2(int num2) {
this.num2 = num2;
}
public int getSum() {
return sum;
}
public void setSum(int sum) {
this.sum = sum;
}
}
迷你添加.jsp
<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
pageEncoding="ISO-8859-1"%>
<%@ page import="add.SumBean2"%>
<!DOCTYPE html>
<html>
<head>
<meta charset="ISO-8859-1">
<title>Sum</title>
</head>
<body>
<form action="MiniAdd.jsp">
<label>Number 1</label><input type="text" name="num1"><br>
<label>Number 2</label><input type="text" name="num2"><br>
<input type="submit" value="Submit"/>
<input type="reset" value="Reset"/>
<jsp:useBean id="SumNumber" class="add.SumBean2" scope="session"/>
<jsp:setProperty name="SumNumber" property="num1" value='<%=request.getParameter("num1") %>'/>
<jsp:setProperty name="SumNumber" property="num2" value='<%=request.getParameter("num2") %>'/>
</form>
<%
int sum = 0;
try {
sum = Integer.parseInt(request.getParameter("num1"))+Integer.parseInt(request.getParameter("num2"));
} catch(Exception e) {}
%>
<jsp:setProperty name="SumNumber" property="sum" value='<%= request.getParameter("sum") %>'/>
Sum = <jsp:getProperty name="SumNumber" property="sum"/>
</body>
</html>
暂无答案!
目前还没有任何答案,快来回答吧!