我正在使用docx4j从HTML生成word文档,但我无法设置下载的文件名。默认情况下,它将servlet名称选为WordDocGenServlet.docx。
任何帮助??
提前致谢!
答案 0 :(得分:1)
你可以。使用您的文件名设置响应标头。像这样的东西
fileName = dateString+"_マイページ情報.xls";
fileName = URLEncoder.encode(fileName,"UTF-8");
try {
response.setContentType("application/ms-excel; charset=UTF-8");
response.setCharacterEncoding("UTF-8");
if(browserType.equals("IE")||browserType.equals("Chrome"))
response.setHeader("Content-Disposition","attachment; filename="+fileName);
if(browserType.endsWith("Firefox"))
response.setHeader("Content-Disposition","attachment; filename*=UTF-8''"+fileName);
} catch (Exception e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}