2016-04-04 19 views
0

"Apache POI" kullanarak bir ".xlsx" dosyası (CustomerData.xlsx) oluşturdum.Apache TomCat Server'da dinamik olarak oluşturduğum bir dosyayı nasıl indirebilirim?

Sorun, dosyanın TomCat Sunucumda oluşturulduğu ve indirmem gerektiğidir.

HttpServletResponse response = null; 

response.setContentType("xlsx"); 
response.setHeader(
    "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet", 
    "attachment; filename=C:\CustomerData.xlsx"); 
try { 
    workbook.write(response.getOutputStream()); 
} catch (IOException e) { 
    // TODO Auto-generated catch block 
    e.printStackTrace(); 
} 

ama ne yazık ki, iş için görünmüyor:

Ben dosyayı indirmek için aşağıdaki kodu çalıştı.

Herhangi bir fikriniz veya öneriniz olması durumunda, yayınlamaktan çekinmeyin.

+0

yazma? http://stackoverflow.com/q/7822758 – BalusC

cevap

1

İçerik türü ve ek bilgilerini çalışmayan tek bir üstbilgiye karıştırıyorsunuz. Eğer [primefaces] etiketlendi gibi

yerine bu yararlıdır,

response.setContentType("application/vnd.openxmlformats-officedocument.spreadsheetml.sheet"); 
response.setHeader("Content-Disposition", "attachment;filename=CustomerData.xlsx"); 
+0

Cevabınız için teşekkür ederiz. Değişiklikleri buna göre uyguladım, ancak maalesef işe yaramıyor. – Origamer7

+2

@StavrosVrakas "çalışmıyor" gerçekten çok fazla bilgi yok. – wero

İlgili konular