title: Dispatch/forward to a servlet that serves static content from a different bundle
body: <p>As a developer completely new to Spring and OSGi, and returning to Tomcat after a long time, I don't even know if I can ask this question properly. But I hope someone will be able to understand where I am stuck and how I should proceed.</p>
  
  <p>The setup includes a Tomcat 7 bundles in the Equinox OSGi container. A bundle provides the "<code>MainDispatcherServlet</code>", which extends <code>org.springframework.web.servlet.DispatcherServlet</code>. Other service bundles register <code>org.springframework.web.servlet.mvc.Controller</code> instances in the OSGi whiteboard which the <code>MainDispatcherServlet</code> listens for. <code>MainDispatcherServlet</code> provides an API to map url-patterns to the registered Controllers, which it in turn uses a <code>SimpleUrlHandlerMapping</code> to identify the handler for individual requests. The service bundles often implement a javax <code>GenericServlet</code>, and wrap it in <code>ServletWrappingController</code> for the registration.</p>
  
  <p>This much works smoothly. Now I need the following</p>
  
  <p><strong>Static Resources</strong></p>
  
  <p>Dispatch to static resources like images and jsps (don't know if they are considered static) in these bundles.</p>
  
  <p>Searching on SO it seems this can be done with some <code>&lt;mvc:resources&gt;</code> magic in the client bundle, even though I don't quite figure out the exact xml. But if I understand right the request would not go through the <code>MainDispatcherServlet</code>, which is a requirement. </p>
  
  <p>So the approach I am taking right now is to use a <code>org.apache.catalina.servlets.DefaultServlet</code> and wrap it in a Controller as described above. Is this a good way to accomplish this? The problem here is that <code>DefaultServlet</code> needs a <code>ServletContext</code> and I don't have one to give it. </p>
  
  <p>Is there easy way a to <em>create</em> a <code>ServletContext</code> that I can inject into the Controller?</p>
  
  <p><strong>Forward to Static Resources</strong></p>
  
  <p>Further, I need another <code>Servlet</code> in the same client bundle to be able to <code>forward</code> to the jsps in the bundle using <code>RequestDispatcher</code>, an additional reason I need a full fledged <code>ServletContext</code>. </p>
  
  <p>In summary, is workable (even if not elegant)? And if so how do I create a ServletConteext? If this is not workable what is the alternative?</p>
  
  <p>All this is quite daunting. Though I am not (cannot :)) ask for implemented prototype, I will appreciate more then a terse instruction like "inject X in Y and wrap it with a Z and you are all set".</p>