Reputation: 331
I have a portlet developed in Liferay platform in which I have added the logic to get the query parameter value from URL. I have got the site: http://localhost:8080/web/guest/example, Now this site is being called from the another external site that is not in Liferay with query parameter at end: http://localhost:8080/web/guest/example?value=test. In Liferay Portlet code I have applied the logic to get the Parameter value from the URL which is not working. It returns the "null" value:
HttpServletRequest httpReq = PortalUtil.getOriginalServletRequest(PortalUtil.getHttpServletRequest(request));
String myValue = httpReq.getParameter("value");
System.out.println(myValue);
I tried this way too but get the same "null" value from Query parameter:
HttpServletRequest httpRequest = PortalUtil.getHttpServletRequest(request);
String myValue = httpRequest.getParameter("value");
System.out.println(myValue);
Any suggestion what I am doing wrong here or how can I get the query parameter value coming from external site?
Upvotes: 1
Views: 2931
Reputation: 100
I just tried the following inside doView()
and it works for me:
HttpServletRequest httpReq = PortalUtil.getHttpServletRequest(renderRequest);
HttpServletRequest httpOrigReq = PortalUtil.getOriginalServletRequest(httpReq);
String myValue = httpOrigReq.getParameter("value");
The only difference (may be) is that I used the RenderRequest-object. (As I don't see the type of your request
-object.)
Upvotes: 1
Reputation: 48057
If you have happened to set
<render-weight>0</render-weight>
<ajaxable>true</ajaxable>
in liferay-portlet.xml
, the portlet would be rendered through Ajax and no longer in the same HTTP-Request. I've tried it: Without these settings your code (the first alternative) ran well (in the doView
method).
However, it's bad practice to rely on access to random request parameters (in a portal) anyway... You should rather construct a full portal URL or use the friendly-URL features for Liferay. That way you're really in the portal world and not in a random servlet/portlet mix.
Upvotes: 1