我有一个将文件发送到客户端的 servlet。是否可以添加重定向以开始下载并将用户重定向到另一个 html 页面?这是我的代码:
protected void processRequest(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
try {
System.out.println("debut transfert fichier a " + request.getRemoteUser() + "/" + request.getRemoteAddr());
response.setContentType("text/plain");
response.setHeader("Content-Disposition",
"attachment;filename=my_file.pdf");
// ServletContext ctx = getServletContext();
File jnlp = new File(PATH);
InputStream is = new FileInputStream(jnlp);
int read = 0;
byte[] bytes = new byte[BYTES_DOWNLOAD];
OutputStream os = response.getOutputStream();
while ((read = is.read(bytes)) != -1) {
os.write(bytes, 0, read);
}
// not workinggetServletContext().getRequestDispatcher("/merci.html").forward(request, response);
os.flush();
os.close();
is.close();
HttpSession session = request.getSession();
//
} catch (Exception ex) {
System.out.println("Erreur inconnu lors transfert :" + ex);
}
谢谢。