views:

103

answers:

2

How can I set a spring bean at application level (declaratively)and use the member of it on jsp ?

+3  A: 

are you using spring-MVC? If so, as part of your controller class, have an instance variable that has your bean injected into it. Then, when handling the request in the controller method, add that instance var to your model and return it. This way it will be accessible in the JSP.

darren
A: 

Actually, rather than having to put it into every request in one (and possibly more controllers), you can use the ServletContextAttributeExporter to have Spring place the bean in the J2EE container's applicationScope and have it available all the time in all of your JSPs. This would be much cleaner and simpler than binding it to your controllers and writing code to make it available to your requests.

Alex Marshall