1.jsp+javabean开发模式
这是一个用jsp作为网页的输出技术,将javabean里封装的属性公开。
2.过程
1).先写javabean里的属性及它的get和set。
package aa;
public class javabean_admin {
private int id;
private String username;
private int password;
public int getId() {
return id;
}
public void setId(int id) {
this.id = id;
}
public String getUsername() {
return username;
}
public void setUsername(String username) {
this.username = username;
}
public int getPassword() {
return password;
}
public void setPassword(int password) {
this.password = password;
}
2).继续写上index.jsp
<%@ page language="java" import="java.util.*" pageEncoding="utf-8"%>
<%
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>慢慢来</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">
</head>
<body>
<jsp:useBean id="aa" class="aa.javabean_admin" /><%--id代表包名--%>
<jsp:setProperty name="aa" property="id" value="1"/>
<jsp:setProperty name="aa" property="username" value="jack" />
<jsp:setProperty name="aa" property="password" value="88337248"/>
<jsp:getProperty name="aa" property="id" />
<br>
<jsp:getProperty name="aa" property="username" />
<br>
<jsp:getProperty name="aa" property="password" />
</body>
</html>