2013-05-21 220 views
1

我的問題是,從HttpServletRequest我怎樣才能得到一個PortletRequest

獲得PortletRequest我把這個句子翻譯:

PortletRequest request = (PortletRequest) HttpServletRequest.getAttribute(); 

我應該投入.getAttribute();

當我在IBM的Portlet開發工廠,我用.getAttribute(Constants.PORTLET_REQUEST) 常量合爲一體.jar

現在我需要在JSR168Portlet做到這一點還是有另一種方式來獲得PortletRequest不使用HttpServletRequest

我希望你能幫助我

回答

0

我假設,因爲你有你正在編寫一個servlet一個HttpServletRequest和沒有PortletRequest。這意味着你不會有PortletRequest。您需要編寫Portlet才能獲得PortletRequests,在這種情況下,API接口和Portlet容器將提供PortletRequest。

我不知道Portlet Factory的內部如何工作,您需要獲得像那樣的PortletRequest,但那不是典型的portlet編程。

0

你說你正在製作一個JSR 168 portlet。

在這種情況下,您的portlet類必須實現javax.portlet.Portlet

爲了實現該接口您實現:

render(RenderRequest, RenderResponse)

processAction(ActionRequest, ActionResponse)

這些由portlet被稱爲容器當它決定渲染你的portl或者從您的portlet處理用戶操作。

請求對象RenderRequestActionRequestPortletRequest s。所以你直接把它作爲一個參數,你不必爲它查詢某些東西。

+0

好吧,我現在從RenderRequest和ActionRequest的父是PortletRequest,但我怎麼得到它。 ActionRequest arequest = new ActionRequest(); 就是這樣嗎? – EddyR

+0

將它作爲第一個參數傳遞給您的'processAction'方法,該方法由portlet容器調用(您不調用此方法)。 – npskirk

+0

感謝您的幫助!!!!!我做的 – EddyR

2

您可以使用這樣的事情:

(PortletRequest) request.getAttribute("javax.portlet.request"); 
(PortletResponse) request.getAttribute("javax.portlet.response"); 

請求和響應的HTTPServletRequestHTTPSevletResponse