user2411858
user2411858

Reputation: 39

spring MVC model attributes in jsp page

When I access simple model data like the username using : ${username} everything seems to be fine. But when I try to use ${userdata.uname} I get an error like :

Could not find property uname in class com.mydom.datahandling.userdata

userdata is java class I add to the ModelAndView

   ModelAndView mav = new ModelAndView("page37");
   mav.addObject("sessionID",ID);
   mav.addObject("userdata",p37userdata);

What do I need to do differently ? This seems to be happening whenever I try to use something other than a primitive type or String. I obviously need a bit more education. Do I need to serialize p37userdata?

userdata is

   public class userdata{
   public String uname;
       public String otherstuff;
   }

Upvotes: 1

Views: 225

Answers (1)

digitaljoel
digitaljoel

Reputation: 26574

The objects you reference from your EL in your JSP should be java beans (or a map). According to wikipedia (the source of all truth) A bean has the following properties:

They are serializable, have a 0-argument constructor, and allow access to properties using getter and setter methods.

So you should probably add getters and setters to your userdata class.

Upvotes: 1

Related Questions