title: Referring path variable in jsp Spring framework
body: <p>I pass couple of objects "Studentdetails" and String-"dept" to JSP. </p>
  
  <p>Question-</p>
  
  <p>How will I refer studentdetail.st.fname in my JSP file? ie; need to refer the firstname from the Student object.</p>
  
  <p>I tried this and its failing - </p>
  
  <pre><code>&lt;form:label path="s.studentdetail.st.fname" class="labels"&gt;First Name&lt;/form:label&gt;
  AND 
  &lt;form:label path="studentdetail.st.fname" class="labels"&gt;First Name&lt;/form:label&gt;
  
  
  
     @RequestMapping(value = "/student", method = RequestMethod.GET)
     public ModelAndView student() {
         Map&lt;String, Object&gt; model = new HashMap&lt;String, Object&gt;();
         model.put("studentdetail", new Studentdetails());
         model.put("department", "dept");
         return new ModelAndView("student", "s", model);
    }
  </code></pre>
  
  <p>Studentdetails:</p>
  
  <pre><code>public class Studentdetails {
      public ContactInfo getCi() {
          return ci;
      }
      public void setCi(ContactInfo ci) {
          this.ci = ci;
      }
      public Student getSt() {
          return st;
      }
      public void setSt(Student st) {
          this.st = st;
      }
      ContactInfo ci;
      Student st;
  }
  </code></pre>
  
  <p>Student:</p>
  
  <pre><code>public class Student {
      private Integer age;
      private String fname;
      private String mname;
      private String lname;
      private String dob;
      private String gender;
      private String birthplace;
      private String nationality;
      private String mothertongue;
      private String religion;
      private Integer id;
  
      public Integer getAge() {
          return age;
      }
  
      public void setAge(Integer age) {
          this.age = age;
      }
  
      public String getFname() {
          return fname;
      }
  
      public void setFname(String fname) {
          this.fname = fname;
      }
  
      public String getMname() {
          return mname;
      }
  
      public void setMname(String mname) {
          this.mname = mname;
      }
  
      public String getLname() {
          return lname;
      }
  
      public void setLname(String lname) {
          this.lname = lname;
      }
  
      public String getDob() {
          return dob;
      }
  
      public void setDob(String dob) {
          this.dob = dob;
      }
  
      public String getGender() {
          return gender;
      }
  
      public void setGender(String gender) {
          this.gender = gender;
      }
  
      public String getBirthplace() {
          return birthplace;
      }
  
      public void setBirthplace(String birthplace) {
          this.birthplace = birthplace;
      }
  
      public String getNationality() {
          return nationality;
      }
  
      public void setNationality(String nationality) {
          this.nationality = nationality;
      }
  
      public String getMothertongue() {
          return mothertongue;
      }
  
      public void setMothertongue(String mothertongue) {
          this.mothertongue = mothertongue;
      }
  
      public String getReligion() {
          return religion;
      }
  
      public void setReligion(String religion) {
          this.religion = religion;
      }
  
      public Integer getId() {
          return id;
      }
  
      public void setId(Integer id) {
          this.id = id;
      }
  
  
  }
  </code></pre>
  
  <p>COntactinfo</p>
  
  <pre><code>public class ContactInfo {
      String addr1;
      String addr2;
      String city;
      String state;
      String pin;
      String country;
      String phone;
      String mobile;
      String email;
      public String getAddr1() {
          return addr1;
      }
      public void setAddr1(String addr1) {
          this.addr1 = addr1;
      }
      public String getAddr2() {
          return addr2;
      }
      public void setAddr2(String addr2) {
          this.addr2 = addr2;
      }
      public String getCity() {
          return city;
      }
      public void setCity(String city) {
          this.city = city;
      }
      public String getState() {
          return state;
      }
      public void setState(String state) {
          this.state = state;
      }
      public String getPin() {
          return pin;
      }
      public void setPin(String pin) {
          this.pin = pin;
      }
      public String getCountry() {
          return country;
      }
      public void setCountry(String country) {
          this.country = country;
      }
      public String getPhone() {
          return phone;
      }
      public void setPhone(String phone) {
          this.phone = phone;
      }
      public String getMobile() {
          return mobile;
      }
      public void setMobile(String mobile) {
          this.mobile = mobile;
      }
      public String getEmail() {
          return email;
      }
      public void setEmail(String email) {
          this.email = email;
      }
  
  }
  </code></pre>
  
  <p>Working code:---</p>
  
  <pre><code>&lt;h2&gt;Student Information&lt;/h2&gt;
  &lt;form:form method="POST" action="/SpringMVC/addStudent" modelAttribute="studentdetail"&gt;
  
      &lt;br&gt;&lt;br&gt;
      &lt;form:label path="st.fname" class="labels"&gt;First Name&lt;/form:label&gt;
      &lt;form:input path="st.fname" class="textbox" /&gt;
  
      &lt;br&gt;&lt;br&gt;
      studentdetail:${studentdetail.st.fname}
      &lt;br&gt;
      Department:${department}
      &lt;br&gt;&lt;br&gt;
  
  &lt;/form&gt;
  </code></pre>
  
  <p>Controller:-</p>
  
  <pre><code>@RequestMapping(value = "/student", method = RequestMethod.GET)
     public ModelAndView student() {
         Map&lt;String, Object&gt; model = new HashMap&lt;String, Object&gt;();
         model.put("studentdetail", new Studentdetails());
         model.put("department", "dept");
         return new ModelAndView("student",model);
  </code></pre>