我写了下一个jsp:
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>JSP Page</title>
<link rel="stylesheet" type="text/css" href="style.css" />
</head>
<body>
<h1>Monster Calculator</h1>
<FORM METHOD="POST" ACTION="Controller">
N1: <input type ="text" name="nr1" value="0">
op: <input type ="text" name="op" value="+">
N2: <input type ="text" name="nr2" value="0">
<INPUT class ="button" TYPE="submit" NAME="actiune" VALUE="Calculate"/>
</FORM>
<jsp:useBean id="binaryOperation" class="beans.BinaryOperation" scope="session"/>
<jsp:setProperty name="binaryOperation" property="*"/>
Message: <jsp:getProperty name="binaryOperation" property="nr1"/>
</body>
问题是我希望下一行:
Message: <jsp:getProperty name="binaryOperation" property="nr1"/>
在运行时显示“Message:0”。
这是豆子:
public class BinaryOperation {
private String nr1 = "";
private String op = "";
private String nr2 = "";
public void setNr1(String nr1) {
this.nr1 = nr1;
}
public void setOp(String op) {
this.op = op;
}
public void setNr2(String nr2) {
this.nr2 = nr2;
}
public String getNr1() {
return nr1;
}
public String getOp() {
return op;
}
public String getNr2() {
return nr2;
}
}
问题出在哪里?
答案 0 :(得分:0)
您的BinaryOperation类是否在包中定义?
这行代码表明您的类在包“bean”中:
<jsp:useBean id="binaryOperation" class="beans.BinaryOperation" scope="session"/>
请检查您的班级是否属于“豆类”包裹。
感谢。
答案 1 :(得分:0)
我在index.jsp和Servlet之间又做了一个jsp文件:
<jsp:useBean id="binOp" class="beans.BinaryOperation" scope="session"/>
<jsp:setProperty name="binOp" property="*"/>
这就是“神奇”。