我在使用 Struts 1.x 下载 PDF 文件时遇到了一点问题。当我实际要下载文件时,我不确定文件路径是什么。到目前为止,我有这个:
protected StreamInfo getStreamInfo(ActionMapping mapping,ActionForm form,
HttpServletRequest request, HttpServletResponse response) throws Exception {
String fileDir="/descargasPDF"; //directory where all files are created and located
String fileName="/tratado.pdf";
String contentType = "application/pdf";
//File file = new File(NOT SURE WHAT GOES HERE);
//I found this on the internet.
//But it doesn't creates the file on the fileDir directory.
File file = new File(request.getRealPath("/WEB-INF")+fileDir+fileName);
FileOutputStream f = new FileOutputStream(file);
......
}
我不太确定我是否真的想将 pdf 文件临时保存在我的 WEB-INF 目录中,但我不知道该怎么做。有谁知道更好的方法来做到这一点?如果是这样,我该怎么做?
谢谢你。
编辑
我忘记指定我正在生成 PDF 并且我正在使用 iText 5.3。