我的代码是这样的,但他还是只能在jsp中显示xml,不能出现对话框让我下载
Element root = new Element("list");
Document doc = new Document(root);
for (int i = 0; i < 5; i++)
{
Element elements = new Element("company");
elements.setAttribute("id", "" + i);
elements.addContent(new Element("company_name").setText("name" + i));
elements.addContent(new Element("company_email").setText("@" + i+ ".aaa"));
root.addContent(elements);
}
response.setHeader("Content-Disposition ","attachment;filename=test.xml\"");
response.setContentType("application/x-msdownload");
XMLOutputter XMLOut = new XMLOutputter();
XMLOut.output(doc, new FileOutputStream("test.xml"));
try
{
FileInputStream fileInputStream = new FileInputStream("test.xml");
OutputStream o = response.getOutputStream();
int i = 0;
while ((i = fileInputStream.read()) != -1)
o.write(i);
fileInputStream.close();
o.flush();
o.close();
}
catch (FileNotFoundException e)
{
e.printStackTrace();
}
catch (IOException e)
{
e.printStackTrace();
}
Element root = new Element("list");
Document doc = new Document(root);
for (int i = 0; i < 5; i++)
{
Element elements = new Element("company");
elements.setAttribute("id", "" + i);
elements.addContent(new Element("company_name").setText("name" + i));
elements.addContent(new Element("company_email").setText("@" + i+ ".aaa"));
root.addContent(elements);
}
response.setHeader("Content-Disposition ","attachment;filename=test.xml\"");
response.setContentType("application/x-msdownload");
XMLOutputter XMLOut = new XMLOutputter();
XMLOut.output(doc, new FileOutputStream("test.xml"));
try
{
FileInputStream fileInputStream = new FileInputStream("test.xml");
OutputStream o = response.getOutputStream();
int i = 0;
while ((i = fileInputStream.read()) != -1)
o.write(i);
fileInputStream.close();
o.flush();
o.close();
}
catch (FileNotFoundException e)
{
e.printStackTrace();
}
catch (IOException e)
{
e.printStackTrace();
}
解决方案 »
免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货