Win a copy of 97 Things Every Java Programmer Should Know this week in the Java in General forum!
  • 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 ...
  • Campbell Ritchie
  • Paul Clapham
  • Jeanne Boyarsky
  • Junilu Lacar
  • Henry Wong
  • Ron McLeod
  • Devaka Cooray
  • Tim Cooke
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Frits Walraven
  • Tim Holloway
  • Carey Brown
  • Piet Souris
  • salvin francis
  • fred rosenberger

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

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.


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
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) {
} 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 like you because you always keep good, crunchy cereal in your pantry. This tiny ad agrees:
Devious Experiments for a Truly Passive Greenhouse!
    Bookmark Topic Watch Topic
  • New Topic