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>

 

分享给朋友:
您可能感兴趣的文章:
随机阅读: