java - How to access bean from controller in Spring MVC? -
i have bean
<bean class="myprogram.filelist">
defined.
now wish bean accessible jsp. how accomplish this?
first thought access bean somewhere in controller method , put model
@requestmapping(value = "/", method = requestmethod.get) public string home(locale locale, model model) { logger.info("welcome home! client locale {}.", locale); filelist filelist = // code access filelist bean model.addattribute("filelist", filelist); return "home"; }
but ether not required or can described somewhere in bean configuration?
update
the answer exposedcontextbeannames
parameter.
first of all, inject bean controller using @autowired annotation:
@autowired private filelist filelist;
then add model did: model.addattribute("filelist", filelist);
.
in jsp use jstl access it. e.g:
some property file list bean: <c:out value="${filelist.someproperty}"/>
Comments
Post a Comment