我正在嘗試在生成excel表單期間發生錯誤時將請求轉發到錯誤頁面。以下是示例代碼。我不知道爲什麼它沒有得到轉發時拋出異常錯誤頁面,它顯示的是空白頁,但不會去我的錯誤頁面sure.`如何使ResourceResponse將請求轉發到liferay portlet中的錯誤頁面
@ResourceMapping("xyz") public void generateExcelExport(ResourceRequest request, ResourceResponse response) { try { //Do all the excel related logic response.setContentType("application/vnd.openxmlformats-officedocument.spreadsheetml.sheet"); response.setProperty("Content-Disposition", "attachment; filename=\"" + XYZ + "\""); workbook.write(response.getPortletOutputStream()); } catch (Exception e) { response.setProperty("Content-Disposition", "inline"); response.setContentType("text/html"); PortletRequestDispatcher dispatcher = request.getPortletSession().getPortletContext().getRequestDispatcher("/WEB-INF/views/html/jsp/error.jsp"); try { dispatcher.forward(request, response); } catch (Exception e1) { log.error("Unable to forward the request from the portlet", e1); } } }
我認爲「setRenderParameter」方法不存在於「ResourceResponse」接口下。是的,它出現在你用在你的案例中的「ActionResponse」中 –
我編輯了我的答案,也許這將有助於弄清楚該怎麼做..我認爲調用渲染請求並在處理此方法之後獲取渲染階段將使它工作... – Smajl
謝謝你的幫助Smajil幸運的男孩。我通過在dispatcher.forward(request,response);'之前添加'dispatcher.include(request,response);'來實現它。儘管我沒有獲得與portlet相同的外觀和感覺,但我現在可以至少顯示一些用戶友好的錯誤消息。 –