当生成 Excel 工作表期间发生错误时,我试图将我的请求转发到错误页面。下面是示例代码。我不确定为什么抛出异常时它没有转发到错误页面,它显示空白页面但肯定不会转到我的错误页面。
@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);
}
} }
我不确定,但我的猜测是您在重定向到错误页面时没有设置任何渲染参数。
试试这个,看看它是否有任何帮助(您可以将其放置在调度程序中而不是线路):
response.setRenderParameter("jspPage", "/WEB-INF/views/html/jsp/error.jsp");
我正在使用这种重定向动作响应但它应该与资源响应还有...
编辑:资源响应不包含 setRenderParameter 方法,但 zou 可以尝试使用以下方法:
使用创建 renderURLresponse.createRenderURL()
。如果使用此 URL 触发请求,它将导致呈现请求/响应(或可以访问该方法的操作请求)。
问题是,您试图在 portlet 的资源阶段重定向到另一个页面(在此阶段未调用渲染阶段)。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)