title: Facelet include of a servlet generated content
body: <p>I'd like to include a servlet generated content in a facelet using ui:include. So far I only got errors.</p>
  
  <p>Note that the servlet works fine, GET requests from a browser are ok.</p>
  
  <p>Note that I can successfully include content from another facelet file, but not when the content is servlet generated.</p>
  
  <p>I googled and stackoverflowed my issue but could not find matching responses.</p>
  
  <p>myfacelet.xhtml (at the root of the webapp, i.e. reached by "http://localhost:8080/mywebapp/myfacelet.xhtml"):</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="UTF-8"?&gt;
  &lt;!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
      "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"&gt;
  &lt;html xmlns="http://www.w3.org/1999/xhtml"
    xmlns:h="http://java.sun.com/jsf/html"
    xmlns:ui="http://java.sun.com/jsf/facelets"&gt;
  &lt;h:head&gt;
    &lt;title&gt;JSF Dynamic Content&lt;/title&gt;
  &lt;/h:head&gt;&lt;h:body&gt;
    &lt;h3&gt;Dynamic content:&lt;/h3&gt;
    &lt;ui:include src="dynamic-content"/&gt;
  &lt;/h:body&gt;
  &lt;/html&gt;
  </code></pre>
  
  <p>MyServlet.java (can be reached by "http://localhost:8080/mywebapp/dynamic-content"):</p>
  
  <pre><code>@WebServlet(name = "DynamicContentServlet", urlPatterns = {"/dynamic-content"})
  public class DynamicContentServlet extends HttpServlet {
    @Override
    public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
      PrintWriter writer = response.getWriter();
      writer.println("&lt;p&gt;Dynamic stuff&lt;/p&gt;");
    }
  }
  </code></pre>
  
  <p>web.xml (JSF related stuff only) :</p>
  
  <pre><code>&lt;context-param&gt;
    &lt;param-name&gt;javax.faces.PROJECT_STAGE&lt;/param-name&gt;
    &lt;param-value&gt;Development&lt;/param-value&gt;
  &lt;/context-param&gt;
  &lt;servlet&gt;
    &lt;servlet-name&gt;FacesServlet&lt;/servlet-name&gt;
    &lt;servlet-class&gt;javax.faces.webapp.FacesServlet&lt;/servlet-class&gt;
  &lt;/servlet&gt;
  &lt;servlet-mapping&gt;
    &lt;servlet-name&gt;FacesServlet&lt;/servlet-name&gt;
    &lt;url-pattern&gt;/faces/*&lt;/url-pattern&gt;
    &lt;url-pattern&gt;*.jsf&lt;/url-pattern&gt;
    &lt;url-pattern&gt;*.faces&lt;/url-pattern&gt;
    &lt;url-pattern&gt;*.xhtml&lt;/url-pattern&gt;
  &lt;/servlet-mapping&gt;
  </code></pre>
  
  <p>For ui:include="/dynamic-content" and urlPatterns="/dynamic-content"
  (or ui:include="/mywebapp/dynamic-content" and urlPatterns="/dynamic-content")
  the error is:</p>
  
  <pre><code>javax.faces.view.facelets.TagAttributeException: /myfacelet.xhtml @12,48 &lt;ui:include src="/dynamic-content"&gt; Invalid path : /dynamic-content
  at com.sun.faces.facelets.tag.ui.IncludeHandler.apply(IncludeHandler.java:152)
  at javax.faces.view.facelets.CompositeFaceletHandler.apply(CompositeFaceletHandler.java:98)
  at javax.faces.view.facelets.DelegatingMetaTagHandler.applyNextHandler(DelegatingMetaTagHandler.java:137)
  at com.sun.faces.facelets.tag.jsf.ComponentTagHandlerDelegateImpl.apply(ComponentTagHandlerDelegateImpl.java:195)
  at javax.faces.view.facelets.DelegatingMetaTagHandler.apply(DelegatingMetaTagHandler.java:120)
  at javax.faces.view.facelets.CompositeFaceletHandler.apply(CompositeFaceletHandler.java:98)
  at com.sun.faces.facelets.compiler.NamespaceHandler.apply(NamespaceHandler.java:93)
  at javax.faces.view.facelets.CompositeFaceletHandler.apply(CompositeFaceletHandler.java:98)
  at com.sun.faces.facelets.compiler.EncodingHandler.apply(EncodingHandler.java:86)
  at com.sun.faces.facelets.impl.DefaultFacelet.apply(DefaultFacelet.java:152)
  at com.sun.faces.application.view.FaceletViewHandlingStrategy.buildView(FaceletViewHandlingStrategy.java:774)
  at com.sun.faces.lifecycle.RenderResponsePhase.execute(RenderResponsePhase.java:100)
  at com.sun.faces.lifecycle.Phase.doPhase(Phase.java:101)
  at com.sun.faces.lifecycle.LifecycleImpl.render(LifecycleImpl.java:139)
  at javax.faces.webapp.FacesServlet.service(FacesServlet.java:594)
  (...)
  at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:671)
  at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:930)
  at java.lang.Thread.run(Thread.java:662)
  </code></pre>
  
  <p>For ui:include="dynamic-content" and urlPatterns="/dynamic-content"
  or ui:include="dynamic-content.bla" and urlPatterns="*.bla",
  the error is:</p>
  
  <pre><code>java.io.FileNotFoundException
  at org.apache.naming.resources.DirContextURLConnection.getInputStream(DirContextURLConnection.java:369)
  at com.sun.faces.facelets.impl.DefaultFaceletCache._getLastModified(DefaultFaceletCache.java:172)
  at com.sun.faces.facelets.impl.DefaultFaceletCache.access$000(DefaultFaceletCache.java:62)
  at com.sun.faces.facelets.impl.DefaultFaceletCache$1.newInstance(DefaultFaceletCache.java:82)
  at com.sun.faces.facelets.impl.DefaultFaceletCache$1.newInstance(DefaultFaceletCache.java:78)
  at com.sun.faces.util.ExpiringConcurrentCache$1.call(ExpiringConcurrentCache.java:99)
  at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:303)
  at java.util.concurrent.FutureTask.run(FutureTask.java:138)
  at com.sun.faces.util.ExpiringConcurrentCache.get(ExpiringConcurrentCache.java:114)
  at com.sun.faces.facelets.impl.DefaultFaceletCache.getFacelet(DefaultFaceletCache.java:121)
  at com.sun.faces.facelets.impl.DefaultFaceletCache.getFacelet(DefaultFaceletCache.java:62)
  at com.sun.faces.facelets.impl.DefaultFaceletFactory.getFacelet(DefaultFaceletFactory.java:256)
  at com.sun.faces.facelets.impl.DefaultFacelet.include(DefaultFacelet.java:366)
  at com.sun.faces.facelets.impl.DefaultFacelet.include(DefaultFacelet.java:346)
  at com.sun.faces.facelets.impl.DefaultFaceletContext.includeFacelet(DefaultFaceletContext.java:199)
  at com.sun.faces.facelets.tag.ui.IncludeHandler.apply(IncludeHandler.java:147)
  at javax.faces.view.facelets.CompositeFaceletHandler.apply(CompositeFaceletHandler.java:98)
  at javax.faces.view.facelets.DelegatingMetaTagHandler.applyNextHandler(DelegatingMetaTagHandler.java:137)
  at com.sun.faces.facelets.tag.jsf.ComponentTagHandlerDelegateImpl.apply(ComponentTagHandlerDelegateImpl.java:195)
  at javax.faces.view.facelets.DelegatingMetaTagHandler.apply(DelegatingMetaTagHandler.java:120)
  at javax.faces.view.facelets.CompositeFaceletHandler.apply(CompositeFaceletHandler.java:98)
  at com.sun.faces.facelets.compiler.NamespaceHandler.apply(NamespaceHandler.java:93)
  at javax.faces.view.facelets.CompositeFaceletHandler.apply(CompositeFaceletHandler.java:98)
  at com.sun.faces.facelets.compiler.EncodingHandler.apply(EncodingHandler.java:86)
  at com.sun.faces.facelets.impl.DefaultFacelet.apply(DefaultFacelet.java:152)
  at com.sun.faces.application.view.FaceletViewHandlingStrategy.buildView(FaceletViewHandlingStrategy.java:774)
  at com.sun.faces.lifecycle.RenderResponsePhase.execute(RenderResponsePhase.java:100)
  at com.sun.faces.lifecycle.Phase.doPhase(Phase.java:101)
  at com.sun.faces.lifecycle.LifecycleImpl.render(LifecycleImpl.java:139)
  at javax.faces.webapp.FacesServlet.service(FacesServlet.java:594)
  (...)
  at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:671)
  at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:930)
  at java.lang.Thread.run(Thread.java:662)
  </code></pre>
  
  <p>Also note that the servlet never gets executed.</p>
  
  <p>What is wrong with my code?</p>
  
  <p>Is the include possible?</p>
  
  <p>How can I achieve it?</p>
  
  <p>Best regards</p>