zoukankan      html  css  js  c++  java
  • JavaBean

    下面一个javaBean实例:

    1、使用普通方式创建javabean的实例

    <%@ page language="java" import="java.util.*" contentType="text/html; charset=utf-8"%>
    <%@ page import="com.po.Users" %>
    <%
    String path = request.getContextPath();
    String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
    %>

    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
    <html>
    <head>
    <base href="<%=basePath%>">

    <title>My JSP 'index.jsp' starting page</title>
    <meta http-equiv="pragma" content="no-cache">
    <meta http-equiv="cache-control" content="no-cache">
    <meta http-equiv="expires" content="0">
    <meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
    <meta http-equiv="description" content="This is my page">
    <!--
    <link rel="stylesheet" type="text/css" href="styles.css">
    -->
    </head>

    <body>
    <%
    Users user = new Users();
    user.setUsername("admin"); //设置用户名
    user.setPassword("123456");//设置密码
    %>
    <h1>使用普通方式创建javabean的实例</h1>
    <hr>
    用户名:<%=user.getUsername() %><br>
    密码:<%=user.getPassword() %><br>
    </body>
    </html>

    <%@ page language="java" import="java.util.*" contentType="text/html; charset=utf-8"%>
    <%
    String path = request.getContextPath();
    String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
    %>

    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
    <html>
    <head>
    <base href="<%=basePath%>">

    <title>My JSP 'index.jsp' starting page</title>
    <meta http-equiv="pragma" content="no-cache">
    <meta http-equiv="cache-control" content="no-cache">
    <meta http-equiv="expires" content="0">
    <meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
    <meta http-equiv="description" content="This is my page">
    <!--
    <link rel="stylesheet" type="text/css" href="styles.css">
    -->
    </head>

    <body>
    <jsp:useBean id="myUsers" class="com.po.Users" scope="page"/>
    <h1>使用useBean动作创建javabean的实例</h1>
    <hr>
    用户名:<%=myUsers.getUsername() %><br>
    密码:<%=myUsers.getPassword() %><br>
    </body>
    </html>

    因为上面程序没有使用setProperty,所以用户名和密码都是null。

    下面使用setProperty:

    JavaBean可以封装数据也可以封装业务逻辑。

  • 相关阅读:
    javsscript闭包的一种使用场景--沙箱
    toString()方法,与call()方法结合;用来进行数据类型检测
    [学习笔记]数论(二)
    [模板]平面最近点对
    [bzoj1670][Usaco2006 Oct]Building the Moat
    [模板]计算几何(一)
    [日常训练]string
    [bzoj3626][LNOI2014]LCA
    [bzoj2732][HNOI2012]射箭
    [学习笔记]半平面交
  • 原文地址:https://www.cnblogs.com/stm32stm32/p/5839604.html
Copyright © 2011-2022 走看看