Win a copy of Modern JavaScript for the Impatient this week in the Server-Side JavaScript and NodeJS forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Paul Clapham
  • Bear Bibeault
  • Junilu Lacar
Sheriffs:
  • Jeanne Boyarsky
  • Tim Cooke
  • Henry Wong
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • salvin francis
  • Frits Walraven
Bartenders:
  • Scott Selikoff
  • Piet Souris
  • Carey Brown

Call spring bean inside JSP/struts2 bean from a JSP

 
Ranch Hand
Posts: 42
  • 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

 
Ranch Hand
Posts: 1936
  • 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
  • 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
  • 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
  • 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.
 
Author
Posts: 12617
IntelliJ IDE Ruby
  • 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
  • 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
Posts: 12617
IntelliJ IDE Ruby
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What's a "Struts 2 bean"?
 
ranger
Posts: 17346
11
Mac IntelliJ IDE Spring
  • 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
 
Everybody's invited. Except this tiny ad:
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop
https://coderanch.com/wiki/718759/books/Building-World-Backyard-Paul-Wheaton
    Bookmark Topic Watch Topic
  • New Topic