0

accessing ServletContext attributes

asked 2009-04-03 19:36:53 +0800

fusion35 gravatar image fusion35
237 2 5

Hi :

I have defined some attributes in the servletcontext like this:

public void contextInitialized(ServletContextEvent event){

ServletContext context = event.getServletContext();

List<State> listState = null;
List<City> listCities = null;
try {
listState = ApiManager.getStateDao().readAllState();
listCities = ApiManager.getCityDao().readAllCity();
} catch (DAOException ex) {
java.util.logging.Logger.getLogger(ContextListener.class.getName()).log(Level.SEVERE, null, ex);
}
context.setAttribute(Constants.listStates, listState);
context.setAttribute(Constants.listCities, listCities);

log.debug("contextInitialized : void");
}


and later am trying to access the same in the intiatior like this:

public void doAfterCompose(Page page, Component[] comp)
throws java.lang.Exception {

ServletContext context = (ServletContext) Executions.getCurrent().getDesktop().getWebApp().getNativeContext();
List listStates = (List)context.getAttribute(Constants.listStates);
page.setVariable("modelStates", listStates);

super.doAfterCompose(page, comp);
}


}

but am not able to get hold of the attributes. What wrong am I doing?

regards

Devinder

delete flag offensive retag edit

2 Replies

Sort by ยป oldest newest

answered 2009-04-06 02:57:37 +0800

robbiecheng gravatar image robbiecheng
1144 2
http://robbiecheng.sys-co...

did you put the declaration of servletcontext listener in your web.xml?

/robbie

link publish delete flag offensive edit

answered 2009-04-06 10:30:56 +0800

fusion35 gravatar image fusion35
237 2 5

Thanks for the reply.

Yes, I did.

regards

Devinder

link publish delete flag offensive edit
Your reply
Please start posting your answer anonymously - your answer will be saved within the current session and published after you log in or create a new account. Please try to give a substantial answer, for discussions, please use comments and please do remember to vote (after you log in)!

[hide preview]

Question tools

Follow

RSS

Stats

Asked: 2009-04-03 19:36:53 +0800

Seen: 511 times

Last updated: Apr 06 '09

Support Options
  • Email Support
  • Training
  • Consulting
  • Outsourcing
Learn More