Java Web同期学習ノートの55、Java Web_JavaBeanを使う

14179 ワード

Java Web_JavaBeanを使う
  • JavaBean
  • を使用する.
    JavaBeanを使う
  • 1.JavaBeanを具体的に知るといいです.基本的には使わないです.各JSPタグのコードは、そのラベルの下のコメント内のコードに相当する.bean.jsp
  • 
    
    
    <html>
    <head>
    <meta charset="UTF-8">
    <title>Insert title heretitle>
    head>
    <body>
    
    	<jsp:useBean id="customer" class="com.xs.javaweb.Customer"
    		scope="request">jsp:useBean>
    	
    	
    	
    	<jsp:useBean id="customer2" beanName="com.xs.javaweb.Customer"
    		type="java.lang.Object" scope="request">jsp:useBean>
    	
    	
    	
    	
    	<jsp:setProperty property="*" name="customer" />
    	<jsp:setProperty property="name" value="xs" name="customer" />
    		customer.setAge(10);
    	--%>
    	
    	
    	id:<jsp:getProperty property="id" name="customer" /><br>
    	name:<jsp:getProperty property="name" name="customer" /><br>
    	
    	
    	age:<jsp:getProperty property="age" name="customer" />
    	
    	--%>
    
    	
    body>
    html>
    
    Custoomer.java
    /**  
     * All rights Reserved,Designed By XS
     * @Title: Customer.java
     * @Package com.xs.javaweb
     * @Description: TODO
     * @author: XS
     * @date: 2019 3 12    8:23:30
     * @version V1.0
     */
    package com.xs.javaweb;
    
    /**   
     * @ClassName: Customer
     * @Description: TODO
     * @author: XS
     * @date: 2019 3 12    8:23:30
     * @version V1.0
     */
    public class Customer {
    	
    	private int id;
    	private String name;
    	private int age;
    	/**   
    	 * @Title: Customer
    	 * @Description: TODO
    	 * @param id
    	 * @param name
    	 * @param age
    	 */
    	public Customer(int id, String name, int age) {
    		super();
    		this.id = id;
    		this.name = name;
    		this.age = age;
    	}
    	/**   
    	 * @Title: Customer
    	 * @Description: TODO
    	 */
    	public Customer() {
    		super();
    		System.out.println("Customer's Constructor...");
    	}
    	/**  
    	 * @return the id
    	 */
    	public int getId() {
    		return id;
    	}
    	/**  
    	 * @param id: the id to set
    	 */
    	public void setId(int id) {
    		this.id = id;
    	}
    	/**  
    	 * @return the name
    	 */
    	public String getName() {
    		return name;
    	}
    	/**  
    	 * @param name: the name to set
    	 */
    	public void setName(String name) {
    		this.name = name;
    	}
    	/**  
    	 * @return the age
    	 */
    	public int getAge() {
    		return age;
    	}
    	/**  
    	 * @param age: the age to set
    	 */
    	public void setAge(int age) {
    		this.age = age;
    	}
    	
    }