使用普通方式创建JavaBean
一 项目要求
使用普通java类,创建javabean实例
二 代码
1、Users.java
package com.po;
/*
* 用户类
* */
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;
}
}
2、index.jsp
<%@ page language="java" import="java.util.*" contentType="text/html; charset=utf-8"%>
<%@ page import="com.po.Users" %>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<base href="<%=basePath%>">
<title>My JSP 'index.jsp' starting page</title>
<meta http-equiv="pragma" content="no-cache">
<meta http-equiv="cache-control" content="no-cache">
<meta http-equiv="expires" content="0">
<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
<meta http-equiv="description" content="This is my page">
<!--
<link rel="stylesheet" type="text/css" href="styles.css">
-->
</head>
<body>
<%
Users user = new Users();
user.setUsername("admin"); //设置用户名
user.setPassword("123456");//设置密码
%>
<h1>使用普通方式创建javabean的实例</h1>
<hr>
用户名:<%=user.getUsername() %><br>
密码:<%=user.getPassword() %><br>
</body>
</html>
三测试
