• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Liutauras Vilda
  • Tim Cooke
  • Jeanne Boyarsky
  • Bear Bibeault
Sheriffs:
  • Knute Snortum
  • paul wheaton
  • Devaka Cooray
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Ron McLeod
  • Piet Souris
  • Ganesh Patekar
Bartenders:
  • Tim Holloway
  • Carey Brown
  • salvin francis

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

 
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
 
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();
}
 
To do a great right, do a little wrong - shakepeare. twisted little ad:
Enterprise-grade Excel API for Java
https://products.aspose.com/cells/java
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!