//创建一个PersonBean类
public class PersonBean {
private String name;
private int age;
public PersonBean(){
System.out.println("创建PersonBean类");
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public int getAge() {
return age;
}
public void setAge(int age) {
this.age = age;
}
@Override
public String toString() {
return "PersonBean [name=" + name + ", age=" + age + "]";
}
}
UseBeanForm.jsp——————————————————————————————————————
<%@ page language= "java" contentType="text/html;charset=UTF-8" %>
<html>
<head>
<meta charset="utf-8">
<title>提交表单</title>
</head>
<body>
<form action="UseBeanDemo.jsp" method="post">
用户名<input type="text" name ="name"/><br>
年龄<input type="text" name ="age"/><br>
<input type="submit" value ="提交"/><br>
</form>
</body>
</html>
UseBeanDemo.jsp————————————————————————————————————
<%@ page language= "java" contentType="text/html;charset=UTF-8" %>
<jsp:useBean id = "person" scope="page" class="com.lovo.javaBean.PersonBean"/>
<html>
<head>
<meta charset="utf-8">
<title>使用javaBean动作</title>
</head>
<body>
<jsp:setProperty property="*" name="person" /><%--获取表单数据 --%>
<h3>姓名:<%=person.getName() %></h3>
<h3>年龄:<%=person.getAge() %></h3>
</body>
</html>