spring mvc - how to display an object on jsp page? -
i m pretty new spring mvc, m trying setup page display user information
i have trouble controler , view.
controler (getdetail returns user object, has 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 error when go on page :
request processing failed; nested exception java.lang.illegalargumentexception: attribute value must not null
i using spring 3, on tomcat6
so hope can tell me doing wrong ...
thank you
modelmap.addattribute()
not permit attribute value null
, , throw illegalargumentexception
if is.
your controller needs check whether result of simpleusermanager.getdetail(code)
returns null
, , try , render result if it's not. if is null
, need appropriate situation.
Comments
Post a Comment