Userregisterbean.java: This is JavaBean.
PackageJavaBean; Public classUserregisterbean {PrivateString username; PrivateString password; Private intAge ; PublicString GetUserName () {returnusername; } Public voidSetusername (String username) { This. Username =username; } PublicString GetPassword () {returnpassword; } Public voidSetPassword (String password) { This. Password =password; } Public intGetage () {returnAge ; } Public voidSetage (intAge ) { This. Age =Age ; } }
Register.html: Registration page
<! DOCTYPE HTML PUBLIC "-//w3c//dtd HTML 4.01 transitional//en" "Http://www.w3.org/TR/html4/loose.dtd" >User registration information:
REGISTER.JSP: Registration Information Processing page
<%@ 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" >class= "Javabean.userregisterbean"/> <jsp:setproperty name= "user" property= "*"/>Registration Success:Use the Bean property method:<br/>User name:<%=user.getusername ()%> <br/>Password:<%=user.getpassword ()%> <br/>Age:<%=user.getage ()%>
To use the GetProperty action:<br/>User name:<jsp:getproperty property= "username" name= "user"/> <br/>Password:<jsp:getproperty property= "password" name= "user"/> <br/>Age:<jsp:getproperty property= "Age" name= "user"/>
Using JavaBean and GetProperty two methods to obtain the registered user's information, and output.
<jsp:usebean id= "user" class= "Javabean.userregisterbean"/>
Equivalent to:
<%
Userregisterbean user =new Userregisterbean ();
%>
The use of JavaBean in JSP