• 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 Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

unable to download xml file

 
Greenhorn
Posts: 17
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Dear All,

I m trying to download the xml file from the server. I m able to get the download dialog box and able to download the file on the client browser, the file contains the print statement given in the jsp file. Its not displaying the original content of xml file. Below is the jsp code. I m not getting where its going wrong.

<%@ page import="java.io.*,java.io.FileInputStream,java.io.InputStream,java.io.File,java.io.FileInputStream,java.net.URL"%>
<%
String fileName = "forma.xml";
String actualFileName = directory + fileName;
out.println("ACTUAL FILE NAME : " + actualFileName +"<BR>");
InputStream inputStream = null;
try {
response.setContentType("application/Octet-Stream");
response.setHeader("Content-Disposition","attachment;filename=" + fileName );
int sizeRead = 256;
byte[] buf = new byte[1024];
File file = new File(actualFileName).getAbsoluteFile();
out.println("FILE : "+file +"<BR>");
URL url = file.toURL();
inputStream = (BufferedInputStream)url.openConnection().getContent();
out.println("INPUT STREAM ......." + inputStream +"<BR>");
while( (sizeRead = inputStream.read(buf)) != -1 ){
out.println(sizeRead);

}
/*FileInputStream fileinputstream = new FileInputStream(file);
byte abyte1[];
int i = (int)file.length();
byte abyte0[] = new byte;
for(int j = 0; j < i; j += fileinputstream.read(abyte0, j, i - j));
abyte1 = abyte0;
out.println("value of abyte1 :"+abyte1); */
} catch(Exception ex) {
out.println("Exception " + ex.getMessage() +"<BR>");
} finally{
try{
//inputStream.close();
}catch(Exception e){
out.println("Exception in finally" + e.getMessage() +"<BR>");
}
}
%>

Thnx in adv.

Regards,
ritu
 
Ranch Hand
Posts: 8945
Firefox Browser Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

response.setContentType("text/xml;charset=ISO-8859-1");

 
Ritu Pande
Greenhorn
Posts: 17
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
dear pradip,

thnx a lot for the reply. but its not working.

reg,
ritu
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic