{"id":236,"date":"2003-01-26T23:33:13","date_gmt":"2003-01-27T03:33:13","guid":{"rendered":"http:\/\/wordpress.cephas.net\/?p=236"},"modified":"2003-01-26T23:33:13","modified_gmt":"2003-01-27T03:33:13","slug":"coldfusion-httpsessionlistener-interface","status":"publish","type":"post","link":"https:\/\/cephas.net\/blog\/2003\/01\/26\/coldfusion-httpsessionlistener-interface\/","title":{"rendered":"ColdFusion &amp; HttpSessionListener interface"},"content":{"rendered":"<p>Couple weeks ago some guys from <a href=\"http:\/\/www.macromedia.com\/\">Macromedia<\/a> stopped by to yack with <a href=\"http:\/\/www.mindseye.com\/\">us<\/a> about what we thought could be improved and\/or added to the next version of <a href=\"http:\/\/www.macromedia.com\/software\/coldfusion\/\">CFMX<\/a>.  One of the things that came up a couple times was that it would be nice to have session <a href=\"http:\/\/msdn.microsoft.com\/library\/default.asp?url=\/library\/en-us\/iisref\/html\/psdk\/asp\/glob6t84.asp\">OnStart<\/a> and <a href=\"http:\/\/msdn.microsoft.com\/library\/default.asp?url=\/library\/en-us\/iisref\/html\/psdk\/asp\/glob2y90.asp?frame=true\">OnEnd<\/a> functionality as well as application <a href=\"http:\/\/msdn.microsoft.com\/library\/default.asp?url=\/library\/en-us\/iisref\/html\/psdk\/asp\/glob4f78.asp\">OnStart<\/a> and <a href=\"http:\/\/msdn.microsoft.com\/library\/default.asp?url=\/library\/en-us\/iisref\/html\/psdk\/asp\/glob6zc4.asp\">OnEnd<\/a>.  Reading this month&#8217;s <a href=\"http:\/\/www.sys-con.com\/java\/archivesa.cfm?volume=08&amp;issue=01\">Java Developer&#8217;s Journal<\/a>, it has an article on the HttpSession object (I&#8217;d link to it, but they charge for their content&#8230; too bad, I bet they&#8217;d be getting alot more traffic and readers if they&#8217;d provide their content for free), which provides multiple listener objects, <a href=\"http:\/\/java.sun.com\/webservices\/docs\/ea2\/api\/javax\/servlet\/http\/HttpSessionListener.html\">HttpSessionListener<\/a>, <a href=\"http:\/\/java.sun.com\/webservices\/docs\/ea2\/api\/javax\/servlet\/http\/HttpSessionBindingListener.html\">HttpSessionBindingListener<\/a>, <a href=\"http:\/\/java.sun.com\/webservices\/docs\/ea2\/api\/javax\/servlet\/http\/HttpSessionAttributeListener.html\">HttpSessionAttributeListener<\/a>, and <a href=\"http:\/\/java.sun.com\/webservices\/docs\/ea2\/api\/javax\/servlet\/http\/HttpSessionActivationListener.html\">HttpSessionActivationListener<\/a>. I don&#8217;t have CFMX here at home, but it seems like it would be possible to write a class that implements those either of those interfaces (probably the sessionCreated() and sessionDestroyed methods of the HttpSessionListener object), register that class in the web.xml of WEB-INF for your application like this:<\/p>\n<p>&lt;listener&gt;<br \/>\n&nbsp;&nbsp;&lt;listener-class&gt;<br \/>\n&nbsp;&nbsp;&nbsp;&nbsp;com.yourApp.yourSessionListener<br \/>\n&nbsp;&nbsp;&lt;\/listener-class&gt;<br \/>\n&lt;\/listener&gt;<\/p>\n<p>Turns out you could do the same type of thing w\/  <a href=\"http:\/\/java.sun.com\/webservices\/docs\/ea2\/api\/javax\/servlet\/ServletContextListener.html\">javax.servlet.ServletContextListener<\/a> [contextDestroyed() and contextInitialized()] and then register:<\/p>\n<p>&lt;listener&gt;<br \/>\n&nbsp;&nbsp;&lt;listener-class&gt;<br \/>\n&nbsp;&nbsp;&nbsp;&nbsp;com.yourApp.yourApplicationListener<br \/>\n&nbsp;&nbsp;&lt;\/listener-class&gt;<br \/>\n&lt;\/listener&gt;<\/p>\n<p>in your web.xml and then&#8230; hypothetically, you&#8217;d have session OnStart, session OnEnd, application OnStart and application OnEnd just like ASP.<\/p>\n<p>I&#8217;ll try it out tomorrow, unless you beat me to it.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Couple weeks ago some guys from Macromedia stopped by to yack with us about what we thought could be improved and\/or added to the next version of CFMX. One of the things that came up a couple times was that it would be nice to have session OnStart and OnEnd functionality as well as application &hellip; <a href=\"https:\/\/cephas.net\/blog\/2003\/01\/26\/coldfusion-httpsessionlistener-interface\/\" class=\"more-link\">Continue reading <span class=\"screen-reader-text\">ColdFusion &amp; HttpSessionListener interface<\/span> <span class=\"meta-nav\">&rarr;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":[],"categories":[7,3],"tags":[],"_links":{"self":[{"href":"https:\/\/cephas.net\/blog\/wp-json\/wp\/v2\/posts\/236"}],"collection":[{"href":"https:\/\/cephas.net\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/cephas.net\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/cephas.net\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/cephas.net\/blog\/wp-json\/wp\/v2\/comments?post=236"}],"version-history":[{"count":0,"href":"https:\/\/cephas.net\/blog\/wp-json\/wp\/v2\/posts\/236\/revisions"}],"wp:attachment":[{"href":"https:\/\/cephas.net\/blog\/wp-json\/wp\/v2\/media?parent=236"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/cephas.net\/blog\/wp-json\/wp\/v2\/categories?post=236"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/cephas.net\/blog\/wp-json\/wp\/v2\/tags?post=236"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}