两个页面,一个bean,bean的代码如下:
package com.bean.www;
public class Person
{
private String username;
private String gender;
private int age;
public String getUsername()
{
return username;
}
public void setUsername(String username)
{
this.username = username;
}
public String getGender()
{
return gender;
}
public void setGender(String gender)
{
this.gender = gender;
}
public int getAge()
{
return age;
}
public void setAge(int age)
{
this.age = age;
}
======================================
第一个beatTest1.jsp,主要代码如下:
<jsp:useBean id="person" class="com.bean.www.Person" scope="request"/>
<jsp:setProperty name="person" property="gender" value="male"/>
<jsp:setProperty name="person" property="age" value="27"/>
<jsp:setProperty property="username" name="person" value="zhangsan"/>
<jsp:getProperty property="username" name="person"/>
<jsp:forward page="beanTest2.jsp"></jsp:forward>
======================================================
第二个jsp页面,beanTest2.jsp
<jsp:getProperty property="username" name="person"/> <!--出错-->
<!--下面这样写是OK的-->
<%
com.bean.www.Person p=(Person)request.getAttribute("person");
%>
<%=p.getUsername() %>
<%=p.getAge() %>
<%=p.getGender() %>
=====================
问题:
不能跨页面使用JavaBean标签??,我在第一个页面useBean,并设置了scope。在第二个页面就不能使用setProperty或者getProperty标签了???只能采用与scope对应的request.getAttribute???
------解决方案--------------------
可以取到的,不过不是直接用<jsp:getProperty>
还是要先用<jsp:useBean id="person" class="com.bean.www.Person" scope="request"/>
然后才用
<jsp:getProperty>