设计Web程序,计算任意两个整数的和,并在网页上显示结果。要求在javabean中实现数据的求和功能。

<%--提交页面input.jsp--%>
<%@ page language="java" import="java.util.*" pageEncoding="utf-8"%>

<html>
  <head>    <title>提交页面</title>  </head>
  
  <body>
    <h3>按下列格式要求,输入两个整数:</h3><br>
    <form action="show.jsp"method="post">
    加   数:<input type="text" name="shuju1"><br><br>
    被加数:<input type="text"name="shuju2"><br><br>
         <input type="submit"value="提交">
    </form>
  </body>
</html>


<%--显示页面show.jsp--%>
<%@ page language="java" import="java.util.*" pageEncoding="GB2312"%>

<html>
  <head>    <title>求和页面</title>  </head>
  
  <body>
  <jsp:useBean id="c" class="beans.Add" scope="request"/>
  <jsp:setProperty name="c" property="*"/>
  <p>
  调用jsp:setProperty做标签显示结果:<br>
  <jsp:getProperty name="c" property="shuju1"/>+
  <jsp:getProperty name="c" property="shuju2"/>=
  <jsp:getProperty name="c" property="sum"/>
  </p>
  </body>
</html>


<%--实现求和页面Add。java--%>
package beans;

public class Add {
	private int shuju1;
	private int shuju2;
	private int sum;
	public int getSum() {
		return shuju1+shuju2;
	}
	public void setSum(int sum) {
		this.sum = sum;
	}
	public Add(){}
	public int getShuju1() {
		return shuju1;
	}
	public void setShuju1(int shuju1) {
		this.shuju1 = shuju1;
	}
	public int getShuju2() {
		return shuju2;
	}
	public void setShuju2(int shuju2) {
		this.shuju2 = shuju2;
	}
	

}

  

时间最会骗人,但也能让你明白,这个世界上没有什么是不能失去的,留下的尽力珍惜,得不到的都不重要
原文地址:https://www.cnblogs.com/www-x/p/7845933.html