i m pretty new to Spring MVC, i m trying to setup a page to display user information
I have trouble with the controler and the view.
Controler (getDetail returns a User object, it has an email field) :
@RequestMapping("/{code}")
public String get(@PathVariable long code,ModelMap model) throws Exception {
model.addAttribute("user",simpleUserManager.getDetail(code));
return "userdetail";
}
in userdetail.jsp :
<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
pageEncoding="ISO-8859-1"%>
<%@ taglib uri="http://www.springframework.org/tags/form" prefix="form"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/functions" prefix="fn"%>
<html>
<head><title><fmt:message key="title"/></title></head>
<body>
User Detail :
${user.email}
</body>
</html>
But i get this error when i go on the page :
Request processing failed; nested exception is java.lang.IllegalArgumentException: Attribute value must not be null
I am using Spring 3, on Tomcat6
So i hope you can tell me what i am doing wrong …
Thank you
ModelMap.addAttribute()does not permit the attribute value to benull, and will throw anIllegalArgumentExceptionif it is.Your controller needs to check whether the result of
simpleUserManager.getDetail(code)returns anull, and only try and render the result if it’s not. If it isnull, you need to do something appropriate to that situation.