This week's book giveaway is in the Performance forum.
We're giving away four copies of The Java Performance Companion and have Charlie Hunt, Monica Beckwith, Poonam Parhar, & Bengt Rutisson on-line!
See this thread for details.
Win a copy of The Java Performance Companion this week in the Performance forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

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

 
purushotham podaralla
Greenhorn
Posts: 29
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 4864
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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 ]
 
purushotham podaralla
Greenhorn
Posts: 29
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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();
}
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic