This week's book giveaway is in the Mac OS forum.
We're giving away four copies of a choice of "Take Control of Upgrading to Yosemite" or "Take Control of Automating Your Mac" and have Joe Kissell on-line!
See this thread for details.
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
Author

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

purushotham podaralla
Greenhorn

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.

Regards,

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 ]

Merrill
Consultant, Sima Solutions
purushotham podaralla
Greenhorn

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) {
response.setContentType("text/xml");
} else if (reportFormat.indexOf(".rpt") > -1) {
response.setContentType("application/rpt");
} else if (reportFormat.indexOf(".pdf") > -1) {
response.setContentType("application/pdf");
} else if (reportFormat.indexOf(".xls") > -1) {
response.setContentType("application/vnd.ms-excel");
}
}
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);
out.flush();
out.close();
} catch (IOException e) {
// TODO Auto-generated catch block
e.getMessage();
}
 
GeeCON Prague 2014
 
subject: how to set .xml, .pdf, .xls, and .rpt in response.setContentType(