我想知道两者之间的区别

PortalUtil.getOriginalServletRequest(portletRequest)


PortalUtil.getHttpServletRequest(portletRequest).

最佳答案

查看Liferay 6的源代码(假设您正在谈论6),您可以看到PortalUtil.getOriginalServletRequest的功能,并将代码放置在下面:

public HttpServletRequest getOriginalServletRequest(
    HttpServletRequest request) {

    HttpServletRequest originalRequest = request;

    while (originalRequest.getClass().getName().startsWith(
                "com.liferay.")) {

        // Get original request so that portlets inside portlets render
        // properly

        originalRequest = (HttpServletRequest)
            ((HttpServletRequestWrapper)originalRequest).getRequest();
    }

    return originalRequest;
}

因此,正如评论中所说,“获取原始请求,以使portlet中的portlet能够正确呈现”。对于嵌套的portlet情况或类似情况,您可能只需要这样做。大多数时候,您只需要使用:
PortalUtil.getHttpServletRequest(portletRequest);

我希望这有帮助!

07-24 13:16