zoukankan      html  css  js  c++  java
  • jsp:setProperty getProperty标签的使用

    1、Person.java  该JavaBean 用户封装信息

    import java.util.Date;
    public class Person {
        private String name = "aaa";
        private String password;
        private int age;
        private Date birthday;
        private Address address;    
        public void setBirthday(Date birthday){
            this.birthday = birthday;
        }    
        public Date getBirthday(){
            return birthday;
        }    
        public void setAge(int age){
            this.age = age;
        }    
        public int getAge(){
            return age;
        }    
        public void setName(String name){
            this.name= name;
            
        }
        public String getName(){
            return name;
        }
        public void setPassword(String password){
            this.password= password;
            
        }
        public String getPassword(){
            return password;
        }
        public Address getAddress() {
            return address;
        }
        public void setAddress(Address address) {
            this.address = address;
        }
    } 

    2,jsp:setProperty getProperty标签的使用

    <%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
    
    
    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
    <html>
      <head>
        <title>jsp:setProperty getProperty标签的使用</title>
      </head>
     
      <body>     
        <!-- jsp:setProperty标签在工作时,它会自动把字符串转成八种基本数据类型 -->
        <!-- 但是jsp:setProperty标签对于复杂类型无法自动进行转换 -->
         <jsp:useBean id="person" class="cn.itcast.Person" scope="page"/>
         
         <jsp:setProperty name="person" property="name" value="qqqq"/>
         <jsp:setProperty name="person" property="password" value="123"/>
         <jsp:setProperty name="person" property="age" value="12"/>
         <jsp:setProperty name="person" property="birthday" value="<%=new Date() %>"/>
         
         <!-- jsp:setProperty标签可以使用请求参数为bean的属性赋值 -->
         <jsp:setProperty name="person" property="name" param="name"/>
         
         <!-- jsp:setProperty标签用所有的请求参数为bean的属性赋值 -->
         <!-- http://localhost:8080/day09/2.jsp?name=flx&password=123&age=34 -->
         <jsp:setProperty name="person" property="*"/>
        
        <%
            System.out.println(person.getName());
            System.out.println(person.getPassword());
            System.out.println(person.getAge());
        %>
        
        
        <jsp:getProperty name="person" property="name"/>
        
      </body>
    </html>
  • 相关阅读:
    记录cacti时间筛选bug的解决办法
    mysql开启远程访问权限
    Mysql 5.7.32 安装cacti-0.8.8h出错
    记录Apache无法解析PHP代码解决方法
    zabbix5.0安装问题:Time zone for PHP is not set
    数据库以及数据表的创建
    小程序框架wepy
    通用的代码总结
    html网页什么样的字体最好看,css设置各种中文字体样式代码
    vue中使用BetterScroll(网上)
  • 原文地址:https://www.cnblogs.com/lichone2010/p/3128265.html
Copyright © 2011-2022 走看看