JSP复习整理(三)基本语法续

时间:2024-01-01 13:54:27

查看注册后的信息:

TestBean.java

package com.hai.xaio.cn;

public class TestBean {
    public String userName;
    public String password;
    public int age;
	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;
	}
	public int getAge() {
		return age;
	}
	public void setAge(int age) {
		this.age = age;
	}

}

register.html

<%@ page language="java" contentType="text/html; charset="
    pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Register</title>
</head>
<body  bgcolor=#EADAEB>
用户注册信息
<br>
<hr>
<form method="get"action="register.jsp">
<table>
    <tr>
       <td>姓名:<input name="userName" type="text"></td>
       </tr>
    <tr>
       <td>密码:<input name="password" type="password"></td>
      </tr>
      <tr>
         <td>年龄:<input name="age" type="text"></td>
      </tr>
      <tr>
         <td><input type=submit value="提交"></td>
       </tr>
</table>
</form>
</body>
</html>

register.jsp

<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<jsp:useBean id="user" scope="page" class="com.hai.xaio.cn.TestBean"/>
<jsp:setProperty name="user" property="*"/>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>register.jsp</title>
</head>
<body bgcolor=#EADAEB>
注册成功:
<br>
<hr>
使用了bean属性方法
<br>
<br>
用户名:
<%=user.getUserName() %>
<br>
<br>
密码:
<%=user.getPassWord() %>
<br>
<br>
年龄:
<%=user.getAge() %>
<br>
<hr>
使用getProperty
<br><br>
用户名:
<jsp:getProperty name="user" property="userName"/>
<br><br>
密码:
<jsp:getProperty property="password" name="user"/>
<br><br>
年龄:
<jsp:getProperty property="age" name="user"/>
<br><br>
</body>
</html>

最终可以显示注册成功后的用户的相关信息。。