Post Reply 
 
Thread Rating:
  • 0 Votes - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
How to export data as pdf in struts using displaytags
12-12-2011, 11:08 PM (This post was last modified: 12-12-2011 11:38 PM by rajasri.)
Post: #1
Photo How to export data as pdf in struts using displaytags
Today you are going to learn about how to export data as pdf in struts using displaytags.
To know more about displaytags and download the example project View pagination in struts Tutorial Click here
By default you can export the data's in csv,excel and xml formats but for pdf and rtf you have to add a jar file named itext.jar.
After downloading itext.jar put it in classpath.

Download the itext.jar file here itext-1.3.jar Download
In the displaytag.properties file you can add your own displaytag properties so that it doesn't take the default names

export.types=csv excel xml pdf rtf
export.excel=true
export.csv=true
export.xml=true
export.pdf=true
export.rtf=true

export.pdf.class=org.displaytag.export.DefaultPdfExportView
export.rtf.class=org.displaytag.export.DefaultRtfExportView
export.excel.label=Export as Excel
export.csv.label=Export as CSV
export.xml.label=Export as Xml
export.rtf.label=Export as RTF
export.pdf.label=Export as PDF

export.xml.filename=s2sgateway.xml
export.csv.filename=s2sgateway.csv
export.excel.filename=s2sgateway.excel
export.pdf.filename=s2sgateway.pdf
export.rtf.filename=s2sgateway.rtf

To avoid the file downloaded in same .do format when exporting,
we have to add the below code in web.xml file

Quote:<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>

Here The media types defines the needed xml,csv,excel,pdf and rtf formats
The Label is used to define your own label
The class that are defined are predefined in itext.jar file
The filename is given because when you click the file for exporting it will download with the name filename.do
so it is best to add the filename so it is downloaded with the format in it say s2sgateway.pdf
If filename not defined the pdf is open in browser itself.
Happy coding....
Find all posts by this user
Add Thank You Quote this message in a reply
Post Reply 


Possibly Related Threads...
Thread: Author Replies Views: Last Post
  Login form authentication using Struts with database mjm 0 302 01-22-2012 02:52 AM
Last Post: mjm
Thumbs Up Struts hiberanate integration tutorial part2 rajasri 7 907 01-20-2012 01:03 AM
Last Post: mjm
Photo Simple Struts-Hibernate Integration tutorial to insert values rajasri 2 1,170 01-15-2012 06:10 PM
Last Post: mukesh1234
Sad Simple Struts Example rajasri 0 142 12-14-2011 03:47 PM
Last Post: rajasri
Tongue Struts Dispatch Action Tutorial with example rajasri 0 580 12-13-2011 01:26 AM
Last Post: rajasri
  Struts hiberanate integration tutorial part2 admin 0 142 11-29-2011 03:48 AM
Last Post: admin

Forum Jump:


User(s) browsing this thread: 1 Guest(s)


WE will share important jobs and updates on facebook so like us to get updates