Can't get URL parameter in doView

679 views Asked by At

I have a Portlet deployed in IBM Portal Server 6.1 which has been mapped to a URL.... enter image description here

I'm trying to add a paramater to a URL like so...

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

And then read the parameter in my doView method like so...

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

But the parameter I've passed in my url is not in the request. i.e. Enumeration params is empty.

Can someone help me figure out on how I can fix this so that I can read a parameter in the URL inside doView?

thanks

2

There are 2 answers

4
Alexander Chernykh On

Try this:

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;
0
Richie On

I've solved this using the following code...

/**
 * 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;
}