建立一个users的java类
package srever;public class Users {private String username;private String password;public Users() {}public String getUsername() {return username;}public void setUsername(String username) {this.username = username;}public String getPassword() {return password;}public void setPassword(String password) {this.password = password;}}
定义一个usebean的jsp文件
<%@ page language="java" contentType="text/html; charset=UTF-8"pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
<head>
<meta charset="ISO-8859-1">
<title>Insert title here</title>
</head>
<body>
<jsp:useBean id="myUsers" class="srever.Users" scope="page"/>
<h1>使用usebean创建javabean的实例</h1><br>
用户名:<%=myUsers.getUsername() %><br>
密码:<%=myUsers.getPassword() %><br>
</body>
</html>
运行结果