以下是ch5_3show.jsp的页面代码:
<%@ page language="java" import="java.util.*" charset="gb2312"pageEncoding="gb2312"%>
<%@ page import="mybean.LoginBean"%>
<html>
<head>
<title>mybean的练习</title>
</head>
<body bycolor="cyan">
<jsp:usebean id="stu" class="mybean.LoginBean" scope="page" />
<jsp:setProperty name="stu" property="*"/>
<%
if(stu.check())
{
%>
<h2>欢迎<jsp:getProperty name="stu"property="loginName"/>
进入考生报名系统
</h2>
<%
}
else
{ %>
<h2>登录失败,单击<a href="javascript:history.back(-1);">
这里重新登录</a></h2>
<%
}
%>
<p>您登录的信息是:
<br>用户姓名:
<jsp:getProperty name="stu"property="loginName"/>
<br>用户密码:
<jsp:getProperty name="stu"property="password"/>
</body>
</html>
以下是ch5_3.jsp的代码:
<%@ page language="java" import="java.util.*" pageEncoding="gb2312"%>
<html>
<head>
<title>练习javaBean实例</title>
</head>
<body bgcolor="cyan">
<form action="ch5_3_show.jsp" method="post"name="form1">
<p>输入用户姓名:
<input type="text" name="loginName"size="20"/>
<br>输入用户密码:
<input type="password" name="password"size="20"/>
<br>输入用户信息:
<input type="submit" name="submit" value="提交"size="6"/>
<br>
<input type="reset" name="reset"value="重置"size="6"/>
</form> <br>
</body>
</html>
以下是建立的bean类:
package mybean;
public class LoginBean {
private String loginName=null;
private String password=null;
public String getLoginName() {
return loginName;
}
public void setLoginName(String loginName) {
this.loginName = loginName;
}
public String getPasssword() {
return password;
}
public void setPasssword(String passsword) {
this.password = passsword;
}
public boolean check(){
if("zhang".equals(loginName)&&"123".equals(password))
return true;
else
return false;
}
public static void main(String[] args) {
// TODO Auto-generated method stub
}
}