☕ book.java
package **com**;
public class **book** {
private **String** bookName;
private **String** price;
private **String** author;
public **String** **getBookName**() {
return bookName;
}
public void **setBookName**(**String** bookName) {
this.bookName = bookName;
}
public **String** **getPrice**() {
return price;
}
public void **setPrice**(**String** price) {
this.price = price;
}
public **String** **getAuthor**() {
return author;
}
public void **setAuthor**(**String** author) {
this.author = author;
}
☕ student.java
package com;
public class Student {
private String name = "小明";
private int age = 29;
private String sex = "男";
public String getName() {
return name;
}
public int getAge() {
return age;
}
public String getSex() {
return sex;
}
}
📑stuinfo.jsp
<%--
Created by IntelliJ IDEA.
User: 13478
Date: 2022/5/6
Time: 15:35
To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
<title>Title</title>
</head>
<body>
<jsp:useBean id="student" class="com.Student"></jsp:useBean>
<div>
<ul>
<li>
姓名:<jsp:getProperty name="student" property="name"></jsp:getProperty>
</li>
<li>
年龄:<jsp:getProperty name="student" property="age"></jsp:getProperty>
</li>
<li>
性别:<jsp:getProperty name="student" property="sex"></jsp:getProperty>
</li>
</ul>
</div>
</body>
</html>
☕ student1.java
package com;
public class Student1 {
private String name;
private int age;
private String gender;
public String getName() {
return name; }
public int getAge() {
return age; }
public String getGender() {
return gender;
}
public void setName(String name) {
this.name = name; }
public void setAge(int age) {
this.age = age;
}
public void setGender(String gender) {
this.gender = gender;
}
}
📑 stuinfo1.jsp
<%--
Created by IntelliJ IDEA.
User: 13478
Date: 2022/5/6
Time: 16:27
To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
<title>Title</title>
</head>
<body>
<jsp:useBean id="student" class="com.Student1"></jsp:useBean>
<jsp:setProperty name="student" property="name" value="朱莉"></jsp:setProperty>
<jsp:setProperty name="student" property="gender" value="女"></jsp:setProperty>
<jsp:setProperty name="student" property="age" value="56"></jsp:setProperty>
<ul>
<li>姓名:<jsp:getProperty name="student" property="name"/></li>
<li>性别:<jsp:getProperty name="student" property="gender"/></li>
<li>年龄:<jsp:getProperty name="student" property="age"/></li>
</ul>
</body>
</html>