wood burning stoves 2.0
The moose likes Struts and the fly likes how to set .xml, .pdf, .xls, and .rpt in response.setContentType( Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Frameworks » Struts
Bookmark "how to set .xml, .pdf, .xls, and .rpt in response.setContentType(" Watch "how to set .xml, .pdf, .xls, and .rpt in response.setContentType(" New topic

how to set .xml, .pdf, .xls, and .rpt in response.setContentType(

purushotham podaralla

Joined: Sep 12, 2007
Posts: 29
Hi All,

i want to display the specified formats from jsp in a separate window. I can able to display excel with in a excel sheet remaining things i could not able to disply. May i know the reason. and i have a doubt to display .rpt from jsp page. Is it possible to display from jsp. Please let me know if its possible.

Thanks in Advance.


Purushotham Podaralla
Merrill Higginson
Ranch Hand

Joined: Feb 15, 2005
Posts: 4864
I'm afraid that how a browser handles the download of different document types is not entirely within your control as a developer. It depends on how each individual user has set up his or her browser and operating system.

For example, when downloading a PDF file, what options I'm presented with as a user is influenced by which operating system I'm using, which browser, whether or not I have the Adobe Acrobat plugin installed on my browser, etc.

The one thing you can do is specify target="_blank" with any link to assure that whatever the browser does, it will do it in a new window.
[ June 21, 2008: Message edited by: Merrill Higginson ]

Consultant, Sima Solutions
purushotham podaralla

Joined: Sep 12, 2007
Posts: 29
Hi Merrill Higginson,
i am using below code to display in different formats. but i am not sure whether .rpt will work or not. i am using Struts frame work. please let me know if you have any solutions.

thanks in advance.
String reportFormat = historyForm.getReportURL();
if (reportFormat != null) {
if (reportFormat.indexOf(".xml") > -1) {
} else if (reportFormat.indexOf(".rpt") > -1) {
} else if (reportFormat.indexOf(".pdf") > -1) {
} else if (reportFormat.indexOf(".xls") > -1) {
response.setHeader("Cache-Control", "no-cache"); // HTTP 1.1
response.setHeader("Cache-Control", "max-age=0");
response.setHeader("Content-disposition", "attachment; filename=" + reportFormat);
try {
byte[] bachUPDoc = (byte[])backupDocuments.get(0);
int l = bachUPDoc.length;//(int) new File(dummy).length();
ServletOutputStream out = response.getOutputStream();
out.write(bachUPDoc, 0, l);
} catch (IOException e) {
// TODO Auto-generated catch block
I agree. Here's the link: http://aspose.com/file-tools
subject: how to set .xml, .pdf, .xls, and .rpt in response.setContentType(
It's not a secret anymore!