public String execute()
sessionMap.put("userBean", userBean); //userBean retrieved from DB
<s:property value="#session.userBean.name" />
Obviously you can't cast it to
UserBean class if the object is not the instance of that class. In the value attribute you have put a string
"#session.userBean.name". Struts parse this string for OGNL expression and if it's a valid expression that returns a value, it will replace it with that value. The returned type is
Object, but this type is determined by
Then property tag writes this object to the
out. It uses
toString() to convert the object to string. And if your object implements this method, then this value would be written.
Looks like your expression returns an
Object, which has instance type
String, so it's already implemented this method.