javabean.comp
package javabean;
public class comp {
private int a;
private int b;
private int sum;
public int getA() {
return a;
}
public void setA(int a) {
this.a = a;
}
public int getB() {
return b;
}
public void setB(int b) {
this.b = b;
}
public int getSum() {
return a+b;
}
public void setSum(int sum) {
this.sum = sum;
}
}
NewFile.jsp
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Insert title here</title>
</head>
<body>
<form action="NewFile1.jsp">
<br><br><br><br><br><br><br>
<div align="center">
一个加数:<input name="a"><br><br>
另一个加数:<input name="b"><br>
<input type="submit" value="add">
</div>
</form>
</body>
</html>
NewFile1.jsp
<%@ page language="java" import="javabean.comp" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Insert title here</title>
</head>
<body>
<jsp:useBean id="c" class="javabean.comp" scope="request"/>
<jsp:setProperty name="c" property="*" />
<jsp:getProperty property="sum" name="c"/>
</body>
</html>