开发者

get HttpServletResponse from liferay portal

I am trying to get the HttpServletResponse开发者_如何学编程 from liferay portal. I am also working with icefaces.

PortletResponse response1 = (PortletResponse)FacesContext.getCurrentInstance().getExternalContext().getResponse();
        HttpServletResponse response = (HttpServletResponse)response1;

I get the following Exception:

Caused by: java.lang.ClassCastException: com.liferay.portlet.RenderResponseImpl cannot be cast to javax.servlet.http.HttpServletResponse


Try PortalUtil.getHttpServletResponse(portletResponse)


May be this Helps

Generate PDF File in Portlet


FacesContext will return PortletRequest/Response objects if you are using the portlet bridge.

What are you trying to do with the HttpServletResponse?

If you are trying to generate binary content, this will only work in the Resource phase of a JSR 286 portlet (otherwise you cannot set headers). It will never work in a JSR 168 portlet. If you need to do this in a JSR 168 portlet, you need to use a helper servlet.

In any case, if you are trying to use a third party lib that requires HttpServletResponse for its API, you can use a PortletRequestDispatcher to dispatch to a JSP or a servlet and then use the HttpServletResponse that is available to you there.


Try getting the native response and then casting it:

FilterServletResponseWrapper filterResponse = (FilterServletResponseWrapper) RequestContextHolder.getRequestContext().getExternalContext().getNativeResponse();
HttpServletResponse response = (HttpServletResponse)filterResponse.getResponse();
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜