關於setProperty的設置
<jsp:setProperty>的屬性設置可以分為四種:
1. 自動匹配:<jsp:setProperty name="實例化對象名稱(id)" property="*"/>
2.指定屬性:<jsp:setProperty name="實例化對象名稱(id)" property="屬性名稱"/>
3.指定參數:<jsp:setProperty name="實例化對象名稱(id)" property="屬性名稱" param="參數名稱"/>
4.指定內容:<jsp:setProperty name="實例化對象名稱(id)" property="屬性名稱" value="內容"/>
實例演示四種設置的應用
我們還是以上一篇文章中的程序來驗證。
biaodan.html <html> <head> <title>WEB開發</title> </head> <body> <form action="javaBean_01.jsp" method="post"> 姓名:<input type="text" name="name"><br> 年齡: <input type="text" name="age"><br> <input type="submit" value="提交"> <input type="reset" value="重置"> </form> </body> </html>
SimpleBean.java
package javaBean01;
public class SimpleBean {
private String name;
private int age;
public SimpleBean(){
}
public void setName(String name){
this.name=name;
}
public void setAge(int age){
this.age=age;
}
public String getName(){
return this.name;
}
public int getAge(){
return this.age;
}
}
SimpleBean_01.jsp
<%@ page language="java" contentType="text/html" pageEncoding="gbk" %>
<html>
<head>
<title>web開發</title>
</head>
<body>
<% request.setCharacterEncoding("gbk");%>
<jsp:useBean id="simple" scope="page" class="javaBean01.SimpleBean"/>
<jsp:setProperty name="simple" property="*"/>
<h3>姓名:<%=simple.getName() %></h3>
<h3>年齡:<%=simple.getAge() %></h3>
</body>
</html>