PDF を提供するために使用しているリソース対応の spring mvc ポートレットがあります。ポートレットから PDF を提供する以前の方法は、サーブレットにリンクして実際に PDF 応答を書き込むことでした。サーブレットのパターンは基本的に次のとおりです。
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
OutputStream out = response.getOutputStream();
FileInputStream certIn = null;
try {
certIn = new FileInputStream(pdfFile);
if (certIn.available() > 0) {
while (certIn.available() > 0) {
out.write(certIn.read());
}
out.flush();
}
} catch (IOException e) {
response.reset();
response.setContentType("text/html");
getServletContext().getRequestDispatcher("/WEB-INF/jsp/error.jsp").include(request, response);
} finally {
if (certIn != null) {
try {
certIn.close();
} catch (IOException e) {
LOG.warn(
"Failed to close FileInputStream", e);
}
}
if (out != null) {
try {
out.close();
} catch (IOException e) {
LOG.warn("Failed to close ServletOutputStream", e);
}
}
}
}
私は現在、リソース対応ポートレットでこれを複製しようとしています。私が抱えている問題は、エラーが発生した場合、エラー jsp にリダイレクトできないことです。
portletContext.getRequestDispatcher() を使用して jsp に転送すると、getOuputStream() の後で getWriter() を呼び出せないというエラーが表示されます。スプリング ModelAndView を error.jsp に返そうとすると、同じエラーが発生します。
ResourceResponse で getOutputStream() を呼び出した後、ユーザーを jsp にリダイレクトする方法を提案できますか?
ありがとう。