码迷,mamicode.com
首页 > 编程语言 > 详细

javaBean

时间:2016-11-04 01:05:48      阅读:236      评论:0      收藏:0      [点我收藏+]

标签:value   请求   imp   参数   函数   利用   setattr   new   org   

1 什么是JavaBean
只要一个类有无参构造函数 能够通过反射创建一个对象 就称之为javaBean

这种方式现在很少用了

<%@page import="com.atguigu.javaweb.Customer"%>
<%@ page language="java" 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>Insert title here</title>
</head>
<body>

<jsp:useBean id="customer" class="com.atguigu.javaweb.Customer"
scope="request"></jsp:useBean>

<jsp:useBean id="customer2" beanName="com.atguigu.javaweb.Customer"
type="java.lang.Object" scope="request"></jsp:useBean>

<%--
Object customer2 = request.getAttribute("customer2");
if(customer2){
customer2 = Class.forName("com.atguigu.javaweb.Customer").newInstance();
request.setAttribute("customer2", customer2);
}
--%>

<!-- 若 property 的值为 *, 省略 value 属性值, 则将自动为所有属性赋值为对应的请求参数的值. -->
<jsp:setProperty property="*" name="customer"/>

<%--
<jsp:setProperty property="name" value="ATGUIGU2" name="customer"/>
--%>

age: <jsp:getProperty property="age" name="customer"/>
<br>
name: <jsp:getProperty property="name" name="customer"/>
<br>
id: <jsp:getProperty property="id" name="customer"/>

<%--
<%= customer.getAge() %>
--%>

<%--
customer.setAge(10);
--%>

<%--
//1. 从 scope(session) 中获取 id(customer) 属性值, 赋给 class(com.atguigu.javaweb.Customer)
//类型的 id(customer) 变量
Customer customer = (Customer)session.getAttribute("customer");

//2. 若属性值为 null, 则利用反射创建一个新的对象, 把该对象赋给 id(customer), 并以 id(customer)
//为属性名让如到 scope(session) 中.
if(customer == null){
customer = (Customer)Class.forName("com.atguigu.javaweb.Customer").newInstance();
session.setAttribute("customer", customer);
}
--%>

</body>
</html>

javaBean

标签:value   请求   imp   参数   函数   利用   setattr   new   org   

原文地址:http://www.cnblogs.com/HJL085/p/6028644.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!