File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
Win a copy of Clojure in Action this week in the Clojure forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Call spring bean inside JSP/struts2 bean from a JSP

 
Patrick Kok
Ranch Hand
Posts: 42
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
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.

Anyone help?
thanks

 
Hong Anderson
Ranch Hand
Posts: 1936
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You should not call Spring managed beans from JSPs.
 
Patrick Kok
Ranch Hand
Posts: 42
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Kengkaj Sathianpantarit wrote:You should not call Spring managed beans from JSPs.


That's why I wanna use ClassPathXmlApplicationContext,
but it only allows me to load applicationContext.xml from classpath.

Anyway to load the spring /WEB-INF/applicationConext.xml from java bean?
I hope FileSystemXmlApplicationContext wouldn't be the answer since I don't want full path to be used.

thanks
 
Patrick Kok
Ranch Hand
Posts: 42
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
okay,
I solved the problem if I implements ApplicationContextAware to the java bean.

thanks
 
Hong Anderson
Ranch Hand
Posts: 1936
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I don't know what you are trying to do. Could you please to post source code and explain what you want to achieve and what is the problem?
Thanks.
 
David Newton
Author
Rancher
Posts: 12617
IntelliJ IDE Ruby
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Patrick Kok
Ranch Hand
Posts: 42
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
thanks
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.

thanks again
 
David Newton
Author
Rancher
Posts: 12617
IntelliJ IDE Ruby
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What's a "Struts 2 bean"?
 
Mark Spritzler
ranger
Sheriff
Posts: 17276
6
IntelliJ IDE Mac Spring
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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)

Also

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.

Mark
 
I agree. Here's the link: http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic