java - Spring-MVC with JSP. How to access a singleton-scoped object from a JSP page? -


A custom format bean was found in the singletons area. And want to use it in JSP page

The first path:

  • Insert the @Autowired (or @ injection) in an administrator
  • Put the bean in the JSP context

== Code ==

@RequestMapping (Method = RequestMethod.GET) Get Public ModelAndView () {ModelAndView Results = New ModelAndView (see " "); Result.addObject ("format", format); Return result; }

The easiest way, but when this bean is needed in almost every page, it hurts.

Second way:

  • Take session-scope from bean
  • Controller (or @ injection) controller Bean
  • has now been stored in the semester session and we can find it in session session

== code ==

 < Code> & lt; Div & gt; $ {SessionScope.format.doSmth ()} & lt; / Div & gt; First of all, there is a need to inject beans - bean is formed only when it is injected with spring reference. Otherwise the bean will not be made and put in session. Second, my IDE does not provide syntax highlighting in that case.  

So the question is:

Is there a way to use singleton-spotted bean in a JSP page without putting it in context with each time and with IDE support ?

i 2 ways to prepare one (singleton scoped) bean in JSP view Will think about

  • Store it as a serviceattel countex attribute. Any bean (including the format bean's own configurable bean) may be in a init-method then it arrives through all the JSP immediately through the LA
  • Use an interceptor to put in the model after all or some controllers, it is available only for those ideas, but it will still work if you later decide to use other views like Velocity or Thiamelph < / Li>

Lake Do not know is how to get the IDE support :-( (Do not use IDEA)


Comments

Popular posts from this blog

java - Can't add JTree to JPanel of a JInternalFrame -

javascript - data.match(var) not working it seems -

javascript - How can I pause a jQuery .each() loop, while waiting for user input? -