Creato da pastuweb.com
Share My Page
My Social Accounts
Account FaceBook Account LinkedIn Account Twitter Account Google Plus Account Git Hub

Display Tag includes a few ready made export views which allow you to export data in CSV, excel, and XML format.

First of all, install Display Tags Library:
http://www.displaytag.org/10/install.html

After that:
Set in the web.xml the filter:

    <!-- Display tag export filter -->
    <filter>
        <filter-name>ResponseOverrideFilter</filter-name>
        <filter class> org.displaytag.filter.ResponseOverrideFilter     </filter-class>
    </filter>
    <filter-mapping>
        <filter-name>ResponseOverrideFilter</filter-name>
        <url-pattern>*.do</url-pattern>
    </filter-mapping>
    <filter-mapping>
        <filter-name>ResponseOverrideFilter</filter-name>
        <url-pattern>*.jsp</url-pattern>
    </filter-mapping>


Include the taglib in the JSP where you want enable exports:

    <%@ taglib uri="http://displaytag.sf.net" prefix="display" %>


Set the buffer page in the JSP where you want enable exports:   

    <%@ page buffer = "16kb" %>


Now you have to develop and create a Servlet or an Action:
    <servlet>
        <servlet-name>servletExport</servlet-name>
        <servlet-class>com..................NewExport</servlet-class>
    </servlet>
    <servlet-mapping>
        <servlet-name>servletExport</servlet-name>
        <url-pattern>/servlets/export</url-pattern>
    </servlet-mapping>


In your servletExport you will have:

    request.setAttribute( "listExample",myList);
    RequestDispatcher dispatcher = request.getRequestDispatcher("/redirect/export.jsp");
    dispatcher.forward(request,response);


In your JSP (export.jsp) you will have this code:

<display:table name="listExample"
    requestURI="/wellness/servlets/export" id="misure_export"
    pagesize="5" cellspacing="10" cellpadding="0" export="true" >
    
    <display:column title="FieldFirst" >
        <c:out value="${misure_export[0] }"/>
    </display:column>

    <display:column title="FieldSecond" >
        <c:out value="${misure_export[1] }"/>
    </display:column>

    <display:setProperty name="export.excel.filename" value="file.xls"/>
    <display:setProperty name="export.xml.filename" value="file.xml"/>
    <display:setProperty name="export.csv.filename" value="file.csv"/>

</display:table >

If you want more information, you can read the Orginal Documentation:
http://www.displaytag.org/10/displaytag.pdf

 

Average (1 Vote)
The average rating is 5.0 stars out of 5.