?
?
具体实例:
写一个JAVABEAN:Person
package com.test.bean; public class Person { private String name ="zhangsan"; private int age =20; private String address = "beijing"; public String getName() { return name; } public void setName(String name) { this.name = name; } public int getAge() { return age; } public void setAge(int age) { this.age = age; } public String getAddress() { return address; } public void setAddress(String address) { this.address = address; } }
?
在jsp页面中使用JAVABEAN
<%@ page language="java" import="com.test.bean.Person" pageEncoding="utf-8"%> <html> <body> <jsp:useBean id="person" class="com.test.bean.Person"/> <jsp:getProperty property="name" name="person"/><br> <jsp:getProperty property="age" name="person"/><br> <jsp:getProperty property="address" name="person"/><br> <jsp:setProperty property="name" value="lisi" name="person"/> <jsp:getProperty property="name" name="person"/><br> <%=person.getName() %> </body> </html>
??
?
?
<jsp:setProperty property="name" name="person" param="helloworld"/>
??http://localhost:8080/servletTest/javabean.jsp?helloworld=aaaa
在地址栏中输入这个URL,在JSP中就能将helloworld参数的值取出,对应后台的源码实现是能过
request.getParameter("helloworld");实现。
?
?
上面是指如在:jsp1中定义了这样的JAVABEAN:
<jsp:useBean id=”person” class=”com.test.bean.Person” scope=”request”/>
?
在jsp2中可以通过如下方式得到前一个页面定义的JAVABEAN
<%Person p = (Person)request.getAttribute(“person”);%>
?