You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tomcat.apache.org by Nam3l3ss <th...@gmail.com> on 2008/06/05 16:57:19 UTC
Get bean from ServletContext on context destruction
Hy!
I have a bean on a jsp page (jsp:UseBean) , with application scope, that uses
some resources that must be freed when the application is stopped/reset.
I'm currently using a context listener to detect when does the servelt context
gets destroyed, but I cannot get the bean from it.
What I want to accomplish is:
1:public void contextDestroyed(ServletContextEvent e){
2: ServletContext t = e.getServletContext();
3: myBean b =(myBean)t.getAttribute("newsbean");
4: if(b!=null){
5: System.out.println("Bean is:"
+(b.holdsResource() ? "!ok" : "ok"));
6: }else{
7: System.out.println("No bean =(");
8: }
9:}
where line 3 should do the trick. How can this be done?
Googling only turned up the reverse, accessing context from a bean,
and the listener is by the webapp in web.xml.
Thanks, nam3l3ss
---------------------------------------------------------------------
To start a new topic, e-mail: users@tomcat.apache.org
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org
Re: Get bean from ServletContext on context destruction
Posted by Mikolaj Rydzewski <mi...@ceti.pl>.
Nam3l3ss wrote:
> I have a bean on a jsp page (jsp:UseBean) , with application scope, that uses
> some resources that must be freed when the application is stopped/reset.
>
> I'm currently using a context listener to detect when does the servelt context
> gets destroyed, but I cannot get the bean from it.
>
Do I understand you correctly: you create a bean in JSP page and then
you want to destroy it in listener?
I usually do both in listener.
--
Mikolaj Rydzewski <mi...@ceti.pl>
---------------------------------------------------------------------
To start a new topic, e-mail: users@tomcat.apache.org
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org