Portlet中的错误页面

Portlet中的错误页面

本文介绍了如何使ResourceResponse将请求转发到Liferay Portlet中的错误页面的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

限时删除!!

在生成Excel工作表时发生错误时,我正在尝试将我的请求转发到错误页面.这是下面的示例代码.我不确定为什么引发异常时它不会转发到错误页面,它显示空白页面,但不能确定地转到我的错误页面.

I am trying to forward my request to error page when error occurs during generating excel sheet. Here is sample code below. I am not sure why it is not getting forwarded to error page when the exception is thrown, it is displaying blank page but not going to my error page for sure.`

        @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);
            }
        } }

推荐答案

也许它不转发是因为响应已经提交,因为您已经在其中写入了一些内容.那可以解释为什么包含作品而前进却没有.

Maybe it is not forwarding because the response has already been committed because you have written something in it. That could explain why include works and forward doesn't.

您可以使用catch块中的resourceResponse.isCommitted()检查响应是否已经提交.

You can check whether the response has already been committed using resourceResponse.isCommitted() in your catch block.

这篇关于如何使ResourceResponse将请求转发到Liferay Portlet中的错误页面的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

1403页,肝出来的..

09-06 13:47