Got a custom formatter bean in a singleton scope. And want to use it in a JSP page.
First way:
==Code==
@RequestMapping(method = RequestMethod.GET)
public ModelAndView get() {
ModelAndView result = new ModelAndView( "view" );
result.addObject( "format", format );
return result;
}
The simpliest way, but when this bean is needed in almost every page, it hurts.
Second way:
==Code==
<div>
${sessionScope.format.doSmth()}
</div>
Bad way too. First, need to inject the bean - the bean is created only when it's injected by Spring Context. Otherwise the bean won't be created and put into the session. Second, my IDE (IDEA) doesn't provide syntax highlighting in that case.
So the question is:
Is there any way to use a singleton-scoped bean in a JSP page without putting it in context every time and with IDE support?
I would think about 2 ways of making a (singleton scoped) bean disponible in JSP view.
init-method
. It is then immediately accessible through EL to all JSP But I really have no idea how to get IDE support :-( (don't use IDEA)
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.