I want to call a spring bean from a jsp page.
I know that spring org.springframework.web.context.support.ServletContextAttributeExporter will do the trick,
but I want to call the spring bean from from the model.
If I use ClassPathXmlApplicationContext in the bean class, then I cannot call the spring session bean.
If the bean is exposed as a Struts 2 action property you shouldn't need to do anything special anyway, but it's unclear what your usecase is.
posted 10 years ago
We use sitemesh for managing our layout, which are jsp in template format.
Since they are not struts2 action, I need to invoke spring bean from jsp page. This was what I was trying to do.
This jsp page is to list all products information in table form with search and sort. There will be one struts2 action and one bean working together on this page.
Now, I use a struts2 bean ( or jsp bean) which implements ApplicationContextAware to get application context and invoke method I need.
Check out the Core Spring documentation, it shows how to integrate with Struts, although I know for Struts 1, but not sure about Struts2/WebWorks(I forgot the real name of the product that changed their name to Struts 2)
That's why I wanna use ClassPathXmlApplicationContext,
but it only allows me to load applicationContext.xml from classpath.
You can load from anywhere, not just ClassPath. Just prefix your location with file: or http: and you can access it by file location, or from within your WEB-INF directory.