-
Available since OmniFaces 1.0
The <o:resourceInclude>
component can be used to catch the output from a JSP or Servlet resource and render it as output to the Faces writer. In effect, this allows you to include both Servlets and JSP pages in e.g. Facelets.
Note that this isn't recommended as a lasting solution, but it might ease a migration from legacy JSP with smelly scriptlets and all on them to a more sane and modern Facelets application.
Demo
Content before Servlet include
Output from Servlet
Content after Servlet include
Demo source code
<p>
Content before Servlet include
<br/>
<o:resourceInclude path="/testservlet" />
<br/>
Content after Servlet include
</p>
package org.omnifaces.showcase.components;
import java.io.IOException;
import jakarta.servlet.ServletException;
import jakarta.servlet.annotation.WebServlet;
import jakarta.servlet.http.HttpServlet;
import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpServletResponse;
@WebServlet("/testservlet")
public class TestServlet extends HttpServlet {
private static final long serialVersionUID = 1L;
@Override
public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
response.getWriter().write("Output from Servlet");
}
}
Documentation & Sources
VDL documentation
API documentation
Java source code
org.omnifaces.component.output.OutputFamily
org.omnifaces.component.output.ResourceInclude
org.omnifaces.io.ResettableBuffer
org.omnifaces.io.ResettableBufferedWriter
org.omnifaces.servlet.HttpServletResponseOutputWrapper
org.omnifaces.io.ResettableBufferedOutputStream
org.omnifaces.servlet.BufferedHttpServletResponse