• JavaBean的一个小例子


    一、创建一个javaBean类: UseBean

    package com.oncall24h.ruchi;
    import java.io.Serializable;
    public class UseBean implements Serializable {
    
        private String username;
        private String password;
        
        public UseBean() {
            super();
        }
        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;
        }
    }

    二、创建表单所在的JSP页面 register.jsp

    <%@ page language="java" contentType="text/html; charset=ISO-8859-1" pageEncoding="ISO-8859-1"%>
    <!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=ISO-8859-1">
    <title>Register</title>
    </head>
    <body>
        <form action="do_register.jsp" method="post">
            USERNAME: <input type="text" name="yonghuming"/>
            PASSWORD: <input type="password" name="mima"/>
            <input type="submit" value="submit"/>
        </form>
    </body>
    </html>

    三、创建表单数据传到的Jsp页面 do_register.jsp

    <%@ page language="java" contentType="text/html; charset=ISO-8859-1"
        pageEncoding="ISO-8859-1"%>
    <!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=ISO-8859-1">
    <title>Handle</title>
    </head>
    <body>
        <jsp:useBean id="user" class= "com.oncall24h.ruchi.UseBean"></jsp:useBean>
        <%--
                user is an arbitrary identifier , UseBean is the defined class name
                which is the same as: UseBean user= new UseBean();
        --%>
        <jsp:setProperty property="username" name="user" param="yonghuming"/>
        <%--
                the same as:
                    user.setUsername("yonghuming");     // yonghuming comes from the form of register.jsp 
         --%>
        <jsp:setProperty property="password" name="user" param="mima"/>
        <%--
                the same as:
                    user.setPassword("mima");     // mima comes from the form of register.jsp 
         --%>
    
        <jsp:getProperty property="username" name="user"/>
        <%--
                the same as:
                    user.getUsername("username");    //username is the property of class UseBean 
         --%>
        <jsp:getProperty property="password" name="user"/>
        <%--
                the same as:
                    user.getPassword("password");    //password is the property of class UseBean 
         --%>
    
    </body>
    </html>
  • 相关阅读:
    Jump Game II
    Trapping Rain Water
    First Missing Positive
    Median of Two Sorted Arrays
    noip2012开车旅行 题解
    AC自动机专题总结
    初探数位DP
    斯坦纳树 [bzoj2595][wc2008]游览计划 题解
    [bzoj3244][noi2013]树的计数 题解
    网络流模型小结
  • 原文地址:https://www.cnblogs.com/ruchicyan/p/Javabean.html
Copyright © 2020-2023  润新知