Professional Documents
Culture Documents
2. Geetha is creating a website which displays the marks of student from two different
java classes. So, define two different java beans and input attributes in Student.java like
studentId,studentNameandMarks.javawhichcontainingclearsegregationofmarksscored in
each subject. Use Spring FrameWork to display all the details of each student to the
browser.
SOLUTION :-
Student.java:-
package com.klu;
publicclass Student {
privateint stId;
privateMark mark;
publicint getStId() {
return stId;
this.stId = stId;
return stName;
this.stName = stName;
publicMark getMark() {
return mark;
this.mark = mark;
}
Mark.java:-
package com.klu;
publicclass Mark {
return maths;
this.maths = maths;
return physics;
this.physics = physics;
return chemistry;
this.chemistry = chemistry;
}
Test.java:-
package com.klu;
import org.springframework.beans.factory.BeanFactory;
importorg.springframework.beans.factory.xml.XmlBeanFactory;
import org.springframework.core.io.ClassPathResource;
import org.springframework.core.io.Resource;
publicclass Test {
BeanFactory factory=newXmlBeanFactory(resource);
student s=(student)factory.getBean("st");
system.out.println("stId:"+s..getstId());
system.out.println("stName:"+s.getstName());
system.out.println("st Mark:");
system.out.println("maths:"+s.getmark().getmaths());
system.out.println("physics:"+e.getmark().getphysics());
system.out.println("chemistry:"+e.getmark().getchemistry());
Applicationcontext.xml:-
<beans
xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:p="http://www.springframework.org/schema/p"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-3.0.xsd">
</bean>
</bean>
</beans>
OUPUTS :-