日期:2014-05-19  浏览次数:20764 次

JAVA EL 的问题求高手解答
首先代码如下
birthday类
package com.yxx;

public class birthday {

private int year;
private int month;
private int day;

public int getYear() {
return year;
}

public void setYear(int year) {
this.year = year;
}

public int getMonth() {
return month;
}

public void setMonth(int month) {
this.month = month;
}

public birthday(int year, int month, int day) {
super();
this.year = year;
this.month = month;
this.day = day;
}

public int getDay() {
return day;
}

public void setDay(int day) {
this.day = day;
}

}

student类

package com.yxx;

public class Student {

private String name;
private int age;
private boolean sex;
private String gName;
private String hahName;

private birthday bday;

public birthday getBday() {
return bday;
}

public void setBday(birthday bday) {
this.bday = bday;
}

public String getHahName() {
return hahName;
}

public void setHahName(String hahName) {
this.hahName = hahName;
}

public String getgName() {
return gName;
}

public void setgName(String gName) {
this.gName = gName;
}

public Student(String name, int age, boolean sex) {
super();
this.name = name;
this.age = age;
this.sex = sex;
}

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 boolean isSex() {
return sex;
}

public void setSex(boolean sex) {
this.sex = sex;
}

}
JSP页面
<body>

<%
Student student = new com.yxx.Student("yangxuxin", 22, true);
birthday bir = new birthday(2012, 4, 7);
student.setBday(bir);
request.setAttribute("student", student);
%>

<%
Student student1 = (Student) request.getAttribute("student");
out.println(student1.getName());
out.println(student1.getBday().getYear());
%>
   
 <br/> year: ${requestScope.student.bday.year }<br/><br/>
   
 <br/> year: ${requestScope.student1.bday.year }
   



</body>

输出的结果是


yangxuxin 2012 
year: 2012


year: 

为什么student可以被识别
而student1不能被识别呢?  

也就是第一个year有输出
第二个没有输出

------解决方案--------------------
那只能路过接分了。
------解决方案--------------------
el拿的对象都是在application、session、request、page中取拿的,你用的requestScope就是从request中取找相应的对象了