controller - Reading the values from session attribute returns only the name in spring MVC -
i have form jsp , on submit redirects success jsp. inputs form elements captured session attribute using value object , rendered in success page.the code goes follows,
form controller:
@controller @requestmapping("/userregistration.htm") @sessionattributes("user") public class usercontroller { private userservice userservice; @autowired public void setuserservice(userservice userservice) { this.userservice = userservice; } @modelattribute("countrylist") public list<country> populatecountrylist() { return userservice.getallcountries(); } @modelattribute("communitylist") public list<community> populatecommunitylist() { return userservice.getallcommunities(); } @requestmapping(method = requestmethod.get) public string showuserform(modelmap model) { user user = new user(); model.addattribute("user", user); return "userform"; } @requestmapping(method = requestmethod.post) public string onsubmit(@modelattribute("user") user user,modelmap model) { userservice.add(user); return "forward:usersuccess.htm";
success controller:
@controller public class usersuccesscontroller { @requestmapping("/usersuccess.htm") public string redirect() { return "usersuccess";
user success jsp:
user details <hr> user name : ${user.getname()} <br/> gender : <c:out value="${user.getgender()}"></c:out> <br/> country : <c:out value="${user.country}"></c:out> <br/> : <c:out value="${user.aboutyou}"></c:out> <br/> community : <c:foreach var="community" items="${user.communitylist}" > <c:out value="${community}"></c:out> </c:foreach> <br /> mailing list: <c:out value="${user.mailinglist} "></c:out>
but output is,
user details -------------------------------------------------------------------------------- user name : ${user.getname()} gender : ${user.getgender()} country : ${user.country} : ${user.aboutyou} community : ${community} mailing list: ${user.mailinglist}
please help. in advance.
i think need add model.addattribute(user);
in onsubmit method, because in view dont use form attributemodelattribute="user"
if use form above attribute, dont need model.addattribute(object);
because attribute somehow links onsubmit @modelattribute("user").
Comments
Post a Comment