まず(JSPファイルの内部で行わない)サーブレットへのあなたのファイルのダウンロードコーディングを動かす..
をこのコードをチェックし、それはuが必要として...それは同じ目的のために私と一緒に働いているのに役立ちます。
package edu.zukrah.servlets;
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;
import javax.servlet.ServletException;
import javax.servlet.ServletOutputStream;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
/**
* Servlet implementation class FileDownload
*/
@WebServlet("/FileDownload")
public class FileDownload extends HttpServlet {
private static final long serialVersionUID = 1L;
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
File f = new File ("E:/pdftest/" + request.getParameter("file"));
//set the content type(can be excel/word/powerpoint etc..)
String type = request.getParameter("type");
response.setContentType (type);
//set the header and also the Name by which user will be prompted to save
response.setHeader ("Content-Disposition", "attachment; filename=\""+request.getParameter("file")+"\"");
//get the file name
String name = f.getName().substring(f.getName().lastIndexOf("/") + 1, f.getName().length());
//OPen an input stream to the file and post the file contents thru the
//servlet output stream to the client m/c
InputStream in = new FileInputStream(f);
try{
ServletOutputStream outs = response.getOutputStream();
int bytesRead;
byte[] buf = new byte[4 * 1024]; // 4K buffer
try {
while ((bytesRead = in.read(buf)) != -1){
outs.write(buf, 0, bytesRead);
}
} catch (IOException ioe) {
ioe.printStackTrace(System.out);
}
System.out.printf(name + ", %.2f kbs downloaded, %.2f mbs downloaded \n",
(f.length()/((double)(1024))),
(f.length()/((double)(1024*1024))));
outs.flush();
outs.close();
in.close();
}catch(Exception e){
e.printStackTrace();
}
}
}
代わりのJSPでこれを行うサーブレットでそれを行う、JSPは動的代わりに壊れ、あなたのExcelがhttp://stackoverflow.com/questions/11226603/createを提出しますバイナリ出力ストリームのHTMLを生成するための文字ライターを使用しています-a-excel-users-to-use-apache-poiを使用してダウンロードする –
[Apache POIを使用してダウンロードするユーザーのためのExcelファイルを作成する]の可能な複製(http://stackoverflow.com/questions/11226603/ apache-poiを使用してユーザーにダウンロードするためのファイルを作成する) –