The use of JavaBean in JSP

Source: Internet
Author: User

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

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.