我有一个表单jsp,并在提交时重定向到一个成功的jsp。表单元素的输入将由会话属性使用值对象捕获并呈现在成功页面中。代码如下,
表单控制器:
@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";
成功控制器:
@Controller
public class UserSuccessController {
@RequestMapping("/userSuccess.htm")
public String redirect()
{
return "userSuccess";
用户成功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/>
About You : <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>
但实际上我得到的输出是,
User Details
--------------------------------------------------------------------------------
User Name : ${User.getName()}
Gender : ${User.getGender()}
Country : ${User.country}
About You : ${user.aboutYou}
Community : ${community}
Mailing List: ${user.mailingList}
请帮忙。提前致谢。