You are on page 1of 10

EP - PRACTICAL – END SEM EXAM

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;

private String stName;

privateMark mark;

publicint getStId() {

return stId;

publicvoid setStId(int stId) {

this.stId = stId;

public String getStName() {

return stName;

publicvoid setStName(String stName) {

this.stName = stName;

publicMark getMark() {

return mark;

publicvoid setMark(Mark mark) {

this.mark = mark;
}

Mark.java:-

package com.klu;

publicclass Mark {

private String maths;

private String physics;

private String chemistry;

public String getMaths() {

return maths;

publicvoid setMaths(String maths) {

this.maths = maths;

public String getPhysics() {

return physics;

publicvoid setPhysics(String physics) {

this.physics = physics;

public String getChemistry() {

return chemistry;

publicvoid setChemistry(String 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 {

publicstaticvoid main(String[] args) {

Resource resource=new ClassPathResource("applicationcontext.xml");

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:-

<?xml version="1.0" encoding="UTF-8"?>

<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 id="mark" class="com.klu.Mark">


<property name="maths" value="50"></property>

<property name="physics" value="48"></property>

<property name="chemistry" value="45"></property>

</bean>

<bean id="st" class="com.klu.Student">

<property name="stId" value="1234567"></property>

<property name="stName" value="vamsi"></property>

<property name="mark" ref="mark"></property>

</bean>

</beans>

OUPUTS :-

You might also like