How to include a JSP page into a custom tag
<p>I am creating a custom tag directive where I have to print a table of data from database.</p>
<p>So far I have created:</p>
<p><strong>JSP page:</strong></p>
<pre class="lang-jsp prettyprint-override"><code> &lt;%@taglib uri=&quot;/WEB-INF/tlds/fact.tld&quot; prefix=&quot;veritis&quot;%&gt;
&lt;html&gt;
    &lt;head&gt;
        &lt;meta http-equiv=&quot;Content-Type&quot; content=&quot;text/html; charset=UTF-8&quot;&gt;
        &lt;title&gt;JSP Page&lt;/title&gt;
    &lt;/head&gt;
    &lt;body&gt;       
        &lt;h1&gt;&lt;veritis:print name=&quot;emp&quot; /&gt;&lt;/h1&gt; 
    &lt;/body&gt;
&lt;/html&gt;
</code></pre>
<p><strong>TLD file:</strong></p>
<pre class="lang-xml prettyprint-override"><code>&lt;?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot;?&gt;
&lt;taglib version=&quot;2.1&quot; xmlns=&quot;http://java.sun.com/xml/ns/javaee&quot;
 xmlns:xsi=&quot;http://www.w3.org/2001/XMLSchema-instance&quot; xsi:schemaLocation=&quot;http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-jsptaglibrary_2_1.xsd&quot;&gt;
 &lt;tlib-version&gt;1.0&lt;/tlib-version&gt;
 &lt;short-name&gt;factorial&lt;/short-name&gt;
  &lt;tag&gt;
      &lt;name&gt;print&lt;/name&gt;
      &lt;tag-class&gt;com.veritis.jsp.FactTag&lt;/tag-class&gt;
      &lt;body-content&gt;empty&lt;/body-content&gt;
    &lt;attribute&gt;
        &lt;name&gt;name&lt;/name&gt;
        &lt;required&gt;false&lt;/required&gt;
    &lt;/attribute&gt;
  &lt;/tag&gt;
&lt;/taglib&gt;
</code></pre>
<p>and a <code>Class</code> file for which fetches data from database using other <code>Class</code> file. This class file also extends <code>TagSupport</code> to overwrite needed TLD methods.</p>
<pre class="lang-java prettyprint-override"><code>public class FactTag extends TagSupport{
    String value=&quot;emp&quot;;
    public String getValue() {
        return value;    }

    public void setValue(String value) {
        this.value = value;
    }
    public int doStartTag(){
        return Tag.SKIP_BODY;
    }
    public int doEndTag() throws JspTagException{

        String emp1=getValue();
            
       try{
           //The following line is to get the JSP Writer Object
           //similar to PrintWriter in Servlet
           JspWriter out=pageContext.getOut();
           
           TableData tbd=new TableData();
           List&lt;Employee&gt; listOfEmp=tbd.getAllEMployees();
           for(Employee emp:listOfEmp)
           {
               System.out.println(emp);
           }
       }catch(Exception e){}
       return Tag.SKIP_PAGE;
    }
   
}
</code></pre>
<p>Now I have data in my <code>List&lt;emp&gt;</code> and I want to print that in JSP file. I could print that by using out object but my requirement is not to use out object rather print by including other JSP file or any other way.</p>
<p><strong>Note:</strong> Though I am taking <code>input(emp)</code> from JSP, I am not using it for now. Rather I am generating a static query to fetch the data.</p>