首先代码如下
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有输出
第二个没有输出
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有输出
第二个没有输出
解决方案 »
- 求SHH的项目?
- 请教一个hibernate继承映射,多态查询的问题
- cmp 数据更新,删除问题
- 求一个基于JBOSS服务器的用JAVA编写的web service简单例子
- struts2 converter 报nullpointer错误
- 任何域名只要指向我的IP就能访问我的网站,Apache,怎么限制?
- Struts问题:使用LookupDispatchAction类时如何在按钮上显示中文
- 怎么由已知路径的xml文件得到inputstream流
- web框架struts,jsf,tapestry,webwork2,Turbine ...大拼比,请进来讨论!!!
- 新手提问,如果我想做j2ee的程序测试,应该做那些方面的配置,装哪些安装包。
- MVC??到底什么东西写在M中,什么写在V里,什么写在C里?求具体指点
- java 并发执行任务 怎么做?
我一直以为是 实例化的student对象原来是request里面的student值