Search code examples
javaspringjspnestedjstl

Access Nested Objects in JSTL on to JSP Page


I am having two classes:

lets say

class ABC{

private String a,b;

public void setA(String a){
this.a = a;
}

public void setB(String b){
this.b = b;
}

public String getA(){
return this.a;
}

public String getB(){
return this.b ;
}

}



class XYZ{

private ABC abc;

public void setABC(ABC abc){
this.abc = abc;
}

public ABC getABC(){
return this.abc;
}

}

Class XYZ having class ABC property.

I want to access class ABC property's a or b in one of the JSP page with the help of JSTL
in this fashion

${XYZ.ABC.A}

Solution

  • To reference beans in the JSP needs to put the object into request.

    request.setAttribute("xyz", xyz);
    

    then access it via ${xyz.abc.a} in the JSP.