Enter your email address:

Delivered by FeedBurner


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, 06:38 PM (This post was last modified: 12-12-2011 07:08 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
[-] The following 1 user says Thank You to rajasri for this post:
ganga (03-29-2012)
Post Reply 


Possibly Related Threads...
Thread: Author Replies Views: Last Post
Thumbs Up Struts hiberanate integration tutorial part2 rajasri 9 2,316 05-02-2012 04:29 PM
Last Post: admin
  Struts hiberanate integration tutorial part2 admin 1 668 05-02-2012 02:36 PM
Last Post: lalithakotha
  Login form authentication using Struts with database mjm 1 4,608 04-27-2012 03:57 PM
Last Post: alexrabe
Photo Simple Struts-Hibernate Integration tutorial to insert values rajasri 2 6,618 01-15-2012 01:40 PM
Last Post: mukesh1234
Sad Simple Struts Example rajasri 0 1,031 12-14-2011 11:17 AM
Last Post: rajasri
Tongue Struts Dispatch Action Tutorial with example rajasri 0 3,204 12-12-2011 08:56 PM
Last Post: rajasri

Forum Jump:


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

Like Our Facebook Page