1.新建JavaBean编写九九乘法计算器代码
package com.javaweb;
public class bean99 {
private int num;
public int getNum( ) {
return num;
}
public void setNum(int num) {
this.num = num;
}
public String print(){
String str="";
for (int i = 1; i <= num; i++) {
for (int j = 1; j <=i; j++) {
str += j+"*"+ i +"="+(i* j);str += "  ";
}
str += "<br>";
}
return str;
}
}
2.新建JSP页面,引入JavaBean并调用
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<%@ page import="com.javaweb.bean99" %>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Insert title here</title>
</head>
<body>
<%
bean99 b=new bean99();
b.setNum(6);
String result=b.print();
out.println(result);
%>
</body>
</html>
3.预览并输出结果