wood burning stoves 2.0*
The moose likes Struts and the fly likes Struts2 - How to save an object through ApplicationAware. Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Frameworks » Struts
Bookmark "Struts2 - How to save an object through ApplicationAware." Watch "Struts2 - How to save an object through ApplicationAware." New topic
Author

Struts2 - How to save an object through ApplicationAware.

Paul Michael Serrano
Ranch Hand

Joined: Nov 22, 2004
Posts: 59
Hi Guys,

I would like to ask if there is a possibility that I could save my objects using the ApplicationAware upon startup of my server by not using it as an action class?

My follow question is, could I implement ApplicationAware together with ServletContextListener so that I could have it saved upon startup of server?

I've tried creating a class like this one, but application.put("languageList", languageList); gives me NullPointerException everytime I start the tomcat.



web.xml snippet


I just need the object languageList to put it in <s:select> tag.

Thanks,
Paul
Ankit Garg
Sheriff

Joined: Aug 03, 2008
Posts: 9291
    
  17

Why are you using ApplicationAware for this?? Just create a ServletContextListener and put the attribute in the ServletContext object...


SCJP 6 | SCWCD 5 | Javaranch SCJP FAQ | SCWCD Links
David Newton
Author
Rancher

Joined: Sep 29, 2008
Posts: 12617

Ankit is correct. ApplicationAware is meaningless outside of a Struts 2 interceptor stack.
Paul Michael Serrano
Ranch Hand

Joined: Nov 22, 2004
Posts: 59
Thanks David and Ankit. I got it working now using the ServletContext object, and could see the value in my JSP.




Paul
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Struts2 - How to save an object through ApplicationAware.
 
Similar Threads
Calling Servlet method from Bean
Getting Database Connection from Servlet
When HttpSessionAttributeListener and HttpSessionBindingListener methods are called?
listener tag is not working in Tomcat
Struts2 that acts as a ServletContextListener