Forums de discussion

Unable to get servlet parameter in portlet

Sunil Sharma, modifié il y a 6 années.

Unable to get servlet parameter in portlet

New Member Publications: 5 Date d'inscription: 19/05/16 Publications récentes
Hi All,

I have created a servlet in my custom Spring MVC portlet.
While hitting servlet from browser with parameter called "paramValue" ,this field value i am getting in servlet .
From servlet i am redirecting to a liferay "public page ex. (http://localhost:8080/group/guest/permit)" where on permit page my custom portlet is deploy.

Now i am not able to get the field value "paramValue" in portlet controller. i was trying with session as well but could not get the desired result.

Please help me resolve this how this paramValue i can access in portlet?
Thanks in advance.
thumbnail
David H Nebinger, modifié il y a 6 années.

RE: Unable to get servlet parameter in portlet

Liferay Legend Publications: 14914 Date d'inscription: 02/09/06 Publications récentes
Sunil Sharma:
While hitting servlet from browser with parameter called "paramValue" ,this field value i am getting in servlet .
From servlet i am redirecting to a liferay "public page ex. (http://localhost:8080/group/guest/permit)" where on permit page my custom portlet is deploy.

Now i am not able to get the field value "paramValue" in portlet controller. i was trying with session as well but could not get the desired result.

Please help me resolve this how this paramValue i can access in portlet?


Okay, take Liferay out of the picture and consider the case of two separate servlets.

Servlet A gets the request, but issues a redirect response back to the browser to have it go to Servlet B.

Servlet B does not get the parameter. Why? Because as far as B is concerned it is just a browser request. If A didn't specify the redirect as "http://host/servlet-b?param=value", the browser is not going to be sending it into B at all.

So this has nothing to do with Liferay or portlets, it is just a lack of understanding of how browsers deal with redirect responses.








Come meet me at the 2017 LSNA!
Sunil Sharma, modifié il y a 6 années.

RE: Unable to get servlet parameter in portlet

New Member Publications: 5 Date d'inscription: 19/05/16 Publications récentes
Thanks David for quick and clear response . i got the problem that you explained for two different servlet.

But still is there any way to get servlet data into liferay portlet , if there is any possibility please help me out.

Thanks
thumbnail
David H Nebinger, modifié il y a 6 années.

RE: Unable to get servlet parameter in portlet

Liferay Legend Publications: 14914 Date d'inscription: 02/09/06 Publications récentes
Redirect params might work. Cookies would work. Persistence would work. That's pretty much it.








Come meet me at the 2017 LSNA!
Sunil Sharma, modifié il y a 6 années.

RE: Unable to get servlet parameter in portlet

New Member Publications: 5 Date d'inscription: 19/05/16 Publications récentes
Thanks David for your useful suggestion,
I have tried with Cookie , adding cookie in servlet then trying to get this in portlet, this cookie is available in browser but i am not able to get this in portlet .

Please find the POC , kindly suggest if something is missing here

Servlet :
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
response.addCookie(new Cookie("permitNumber", request.getParameter("permitNumber")));

response.sendRedirect("http://localhost:8080/group/guest/permit");
}

In Portlet render()
================

@RenderMapping
public String render(RenderRequest renderRequest, RenderResponse renderResponse) throws Exception {
Cookie cookies[]= renderRequest.getCookies(); // i think this renderRequest is different from HttpServletRequest obj

for(Cookie cookie : cookies ){

_log.info("Cookie Name="+cookie.getName()+", Cookie Value ="+cookie.getValue());
}
}

I would be great help
Thanks
thumbnail
Shivam Aggarwal, modifié il y a 6 années.

RE: Unable to get servlet parameter in portlet

Regular Member Publications: 122 Date d'inscription: 18/01/12 Publications récentes
I am able to retrieve all cookie values(default+custom) using the described methodology
Couple of quick checks Sunil,please confirm on the same:

1)You can see the cookies set in browser
2)Page is correctly redirecting
3)In render phase,is the cookie array coming as empty for you or are you not getting the required cokkie value?
Sunil Sharma, modifié il y a 6 années.

RE: Unable to get servlet parameter in portlet

New Member Publications: 5 Date d'inscription: 19/05/16 Publications récentes
Thanks Shivam ,

As mentioned in query please find the below comment for the same :

1)You can see the cookies set in browser
Comment : Yes , I am able to see the cookies that been set .

2)Page is correctly redirecting
Comment : Yes , It is redirecting to the page.

3)In render phase,is the cookie array coming as empty for you or are you not getting the required cokkie value?

Comment : I am getting the cookie array in render phase but the cookies that required is not getting .

It would be great help for me , Please let me know if something is missing there.
Thanks in advance .
thumbnail
Shivam Aggarwal, modifié il y a 6 années.

RE: Unable to get servlet parameter in portlet

Regular Member Publications: 122 Date d'inscription: 18/01/12 Publications récentes
Can you try without redirect and check if the cookie set in action phase is available in render phase of the same portlet?