无法在doView中获取URL参数

时间:2015-06-19 06:30:48

标签: portal websphere-portal

我在IBM Portal Server 6.1中部署了一个已映射到URL的Portlet .... enter image description here

我试图在这样的网址中添加一个参数...

http://localhost:10038/wps/myportal/StockOnHandPortlet?myParameter=false

然后在我的doView方法中读取参数,就像这样......

         HttpServletRequest originalRequest = ((HttpServletRequest)((HttpServletRequestWrapper)request).getRequest());
         Enumeration params = originalRequest.getParameterNames();
         while(params.hasMoreElements()){
            String paramName = (String)params.nextElement();
            System.out.println(paramName + " = " + originalRequest.getParameter(paramName));
        }

但我在我的网址中传递的参数不在请求中。即枚举参数是空的。

有人可以帮我弄清楚如何解决这个问题,以便我可以在doView内的URL中读取参数吗?

感谢

2 个答案:

答案 0 :(得分:0)

试试这个:

import com.ibm.wps.engine.ExtendedLocaleRequest;
import com.ibm.wps.engine.PortalRequestWrapper;
import com.ibm.ws.portletcontainer.portlet.PortletUtils;

HttpServletRequest r1 = PortletUtils.getHttpServletRequest((RenderRequest) r);
PortalRequestWrapper r2 = (PortalRequestWrapper) r1;
ExtendedLocaleRequest r3 = (ExtendedLocaleRequest) r2.getRequest();
HttpServletRequest r4 = (HttpServletRequest) r3.getRequest();
return r4;

答案 1 :(得分:0)

我已使用以下代码解决了这个问题......

/**
 * Get the original http request 
 * 
 * @param request the http request
 * @return the original http request
 */
private HttpServletRequest getHttpServletRequest(PortletRequest request){
    HttpServletRequest httpServletRequest = (HttpServletRequest)request;
    while(httpServletRequest instanceof HttpServletRequestWrapper){
        HttpServletRequestWrapper httpServletRequestWrapper = (HttpServletRequestWrapper)httpServletRequest;
        httpServletRequest =  (HttpServletRequest)httpServletRequestWrapper.getRequest();
    }
    return httpServletRequest;
}