UserRegisterBean.java:这是JavaBean
package JavaBean; public class UserRegisterBean { private String username; private String password; private 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:注册页面 <!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>Insert title here</title> </head> <body> 用户注册信息: <hr> <form action="register.jsp" method="get"> <table> <tr> <td>姓名:<input name="username" type="text" size="16"></td> </tr> <tr> <td>密码:<input name="password" type="password" size="18"></td> </tr> <tr> <td>年龄:<input name="age" type="text" size="16"></td> </tr> <tr> <td><input type="submit" value="提交"></td> </tr> </table> </form> <hr> </body> </html>
register.jsp:注册信息处理页面
<%@ page 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"> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"> <title>处理用户注册信息页面</title> </head> <body> <jsp:useBean id="user" scope="application" class="JavaBean.UserRegisterBean" /> <jsp:setProperty name="user" property="*" /> 注册成功: <hr/> 使用Bean属性方法: <br/> 用户名:<%=user.getUsername() %> <br/> 密码:<%=user.getPassword() %> <br/> 年龄:<%=user.getAge() %> <hr/> 使用getProperty动作: <br/> 用户名:<jsp:getProperty property="username" name="user"/> <br/> 密码:<jsp:getProperty property="password" name="user"/> <br/> 年龄:<jsp:getProperty property="age" name="user"/> <hr/> </body> </html>
分别用 JavaBean 和 getProperty 两种方法处理获得注册用户的信息,并输出.
<jsp:useBean id="user" class="JavaBean.UserRegisterBean" />等价于:<%
UserRegisterBean user =new UserRegisterBean();
%>
时间: 2024-10-17 03:17:36