JAVA EL 的问题求高手解答

yangxuxinzzzz 2012-04-07 02:25:56
首先代码如下
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有输出
第二个没有输出
...全文
97 3 打赏 收藏 转发到动态 举报
写回复
用AI写文章
3 条回复
切换为时间正序
请发表友善的回复…
发表回复
VanBaston 2012-04-10
  • 打赏
  • 举报
回复
el拿的对象都是在application、session、request、page中取拿的,你用的requestScope就是从request中取找相应的对象了
zhucegepp 2012-04-07
  • 打赏
  • 举报
回复
那只能路过接分了。
yangxuxinzzzz 2012-04-07
  • 打赏
  • 举报
回复
这个问题ok了
我一直以为是 实例化的student对象

原来是request里面的student值

67,513

社区成员

发帖
与我相关
我的任务
社区描述
J2EE只是Java企业应用。我们需要一个跨J2SE/WEB/EJB的微容器,保护我们的业务核心组件(中间件),以延续它的生命力,而不是依赖J2SE/J2EE版本。
社区管理员
  • Java EE
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧