| <html><head> | |
| <meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1"> | |
| <title>4.6 Programmatic Access to the Servlet Context</title><link rel="stylesheet" href="css/stylesheet.css" type="text/css"><meta name="generator" content="DocBook XSL Stylesheets V1.74.0"><link rel="home" href="index.html" title="Virgo Programmer Guide"><link rel="up" href="ch04.html" title="4. Developing Applications"><link rel="prev" href="ch04s05.html" title="4.5 Using Spring, Spring DM, and Blueprint"><link rel="next" href="ch04s07.html" title="4.7 Web Application Manifest Processing"><!--Begin Google Analytics code--><script type="text/javascript"> | |
| var gaJsHost = (("https:" == document.location.protocol) ? "https://ssl." : "http://www."); | |
| document.write(unescape("%3Cscript src='" + gaJsHost + "google-analytics.com/ga.js' type='text/javascript'%3E%3C/script%3E")); | |
| </script><script type="text/javascript"> | |
| var pageTracker = _gat._getTracker("UA-2728886-3"); | |
| pageTracker._setDomainName("none"); | |
| pageTracker._setAllowLinker(true); | |
| pageTracker._trackPageview(); | |
| </script><!--End Google Analytics code--></head><body bgcolor="white" text="black" link="#0000FF" vlink="#840084" alink="#0000FF"><div class="navheader"><table width="100%" summary="Navigation header"><tr><th colspan="3" align="center">4.6 Programmatic Access to the Servlet Context</th></tr><tr><td width="20%" align="left"><a accesskey="p" href="ch04s05.html">Prev</a> </td><th width="60%" align="center">4. Developing Applications</th><td width="20%" align="right"> <a accesskey="n" href="ch04s07.html">Next</a></td></tr></table><hr></div><div class="section" lang="en"><div class="titlepage"><div><div><h2 class="title" style="clear: both"><a name="developing-applications-programmatic-access"></a>4.6 Programmatic Access to the Servlet Context</h2></div></div></div><p> | |
| This section describes how to programmatically access the servlet context to obtain the WebApplicationContext or the BundleContext. | |
| </p><div class="section" lang="en"><div class="titlepage"><div><div><h3 class="title"><a name="developing-applications-programmatic-access-web"></a>Programmatic Access to Web Features</h3></div></div></div><div class="section" lang="en"><div class="titlepage"><div><div><h4 class="title"><a name="developing-applications-programmatic-access-web-application-context"></a>Programmatic Access to the WebApplicationContext</h4></div></div></div><p> | |
| The Virgo Server for Apache Tomcat automatically creates a <code class="literal">WebApplicationContext</code> | |
| for Web Application Bundles and WAR files. When used in conjunction with an | |
| an auto-configured Spring MVC <code class="literal">DispatcherServlet</code>, | |
| there is generally no need to access the <code class="literal">WebApplicationContext</code> | |
| programmatically, since all components of the web application are configured | |
| within the scope of the <code class="literal">WebApplicationContext</code> | |
| itself. However, if you wish to access the <code class="literal">WebApplicationContext</code> | |
| you can do so via the web application’s <code class="literal">ServletContext</code>. | |
| Virgo stores the bundle’s | |
| <code class="literal">WebApplicationContext</code> in the ServletContext under | |
| the attribute name "<code class="literal">BSN-ApplicationContext</code>", where | |
| <code class="literal">BSN</code> is the <code class="literal">Bundle-SymbolicName</code> | |
| of your WAR or Web Application Bundle. | |
| </p><p> | |
| Alternatively, since Virgo also stores the | |
| <code class="literal">WebApplicationContext</code> under the attribute name | |
| with the value of the <code class="literal">WebApplicationContext.ROOT_WEB_APPLICATION_CONTEXT_ATTRIBUTE</code> | |
| constant, you may choose to use Spring MVC’s WebApplicationContextUtils’ | |
| <code class="literal">getWebApplicationContext(servletContext)</code> | |
| or | |
| <code class="literal">getRequiredWebApplicationContext(servletContext)</code> | |
| methods to access the <code class="literal">WebApplicationContext</code> without providing | |
| an explicit attribute name. | |
| </p></div><div class="section" lang="en"><div class="titlepage"><div><div><h4 class="title"><a name="developing-applications-programmatic-access-web-bundle-context"></a>Programmatic Access to the BundleContext</h4></div></div></div><p> | |
| As required by the OSGi Web Applications specification, you can access the | |
| <code class="literal">BundleContext</code> of your WAR or Web Application Bundle via the web application’s | |
| <code class="literal">ServletContext</code>. The bundle context is stored in the | |
| <code class="literal">ServletContext</code> under the attribute name <code class="literal">osgi-bundlecontext</code>. | |
| </p></div></div></div><!--Begin LoopFuse code--><script src="http://loopfuse.net/webrecorder/js/listen.js" type="text/javascript"></script><script type="text/javascript"> | |
| _lf_cid = "LF_48be82fa"; | |
| _lf_remora(); | |
| </script><!--End LoopFuse code--><div class="navfooter"><hr><table width="100%" summary="Navigation footer"><tr><td width="40%" align="left"><a accesskey="p" href="ch04s05.html">Prev</a> </td><td width="20%" align="center"><a accesskey="u" href="ch04.html">Up</a></td><td width="40%" align="right"> <a accesskey="n" href="ch04s07.html">Next</a></td></tr><tr><td width="40%" align="left" valign="top">4.5 Using Spring, Spring DM, and Blueprint </td><td width="20%" align="center"><a accesskey="h" href="index.html">Home</a></td><td width="40%" align="right" valign="top"> 4.7 Web Application Manifest Processing</td></tr></table></div></body></html> |