掲示板

Passing actionRequest params using actionResponse.sendRedirect

thumbnail
11年前 に Michael Bravo によって更新されました。

Passing actionRequest params using actionResponse.sendRedirect

New Member 投稿: 20 参加年月日: 12/04/26 最新の投稿
We are using a third party payment processing vendor that requires the form data be posted from a static html form.

I've created a portlet action, using MVCPortlet, where we pull data from the form, persist it using liferay services, and then TRY to forward processing to a static JSP that redirects with a javascript event sending the form data that we collected in the MVC action.

When using actionResponse.sendRedirect, I CAN"T seem to get the request parameters to pass when using:

actionRequest.setAttribute("chargetotal", chargeTotal);
actionResponse.sendRedirect(redirectJSP);

(this is the method by which we would ahve to do it in order to make the refferring page a static URL and not the dynamic URL that liferay generates using the setRenderParameter...


I can get them to pass using:

actionRequest.setAttribute("chargetotal", chargeTotal);
actionResponse.setRenderParameter("jspPage", redirectJSP);

The question is. Is there a way to pass the actionRequest using the actionResponse.sendRedirect(redirectJSP); by setting some configuration or something. OR is there a way to use actionResponse.setRenderParameter("jspPage", redirectJSP); so that the URL is a static url and not the dynamically generated one?

Thanks in advance.
~Michael Bravo
thumbnail
11年前 に Amit Doshi によって更新されました。

RE: Passing actionRequest params using actionResponse.sendRedirect

Liferay Master 投稿: 550 参加年月日: 10/12/29 最新の投稿
Hi Bravo,

There are so many ways you can pass the parameter. Below are some of them.

1) Using Session.



actionRequest.getPortletSession().setAttribute("chargetotal", chargetotal);


2) In Request itself as you required. Please check below code for the same.


String redirectJSP= "/sample.jsp"
		redirectJSP += "&chargetotal="+chargetotal;



Hope it helps.

Thanks & Regards,
Amit Doshi
thumbnail
11年前 に Michael Bravo によって更新されました。

RE: Passing actionRequest params using actionResponse.sendRedirect

New Member 投稿: 20 参加年月日: 12/04/26 最新の投稿
Amit,

Thanks for the response! I'll give it a try.

Mike B.
thumbnail
11年前 に Michael Bravo によって更新されました。

RE: Passing actionRequest params using actionResponse.sendRedirect

New Member 投稿: 20 参加年月日: 12/04/26 最新の投稿
Hi Amit,

Sorry to bother again. The first solution would be ideal for our project. After redirecting, I get a bean not in scope. I am using session as you mentioned, then do a sendRedirect, like this:

// setting value from the form action in a bean called ChargeTotal
ChargeTotal chargeTotal = new ChargeTotal();
chargeTotal.setTotal(actionRequest.getParameter("chargetotal"));

// setting the attribute in session
actionRequest.getPortletSession().setAttribute("chargeTotal", chargeTotal);

// sending redirect to the redirect JSP
actionResponse.sendRedirect(actionRequest.getContextPath()+redirectJSP);



In the JSP i am trying to read the bean like this:

<jsp:useBean id="chargeTotal" type="com.emory.law.registration.ChargeTotal" scope="session" />

Tomcat throws this error: (Partial Stack Trace)

java.lang.InstantiationException: bean chargeTotal not found within scope
org.apache.jsp.html.registration.redirect_jsp._jspService(redirect_jsp.java:139)
org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70)
javax.servlet.http.HttpServlet.service(HttpServlet.java:722)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:432)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:390)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:334)
javax.servlet.http.HttpServlet.service(HttpServlet.java:722)
com.liferay.portal.kernel.servlet.filters.invoker.InvokerFilterChain.doFilter(InvokerFilterChain.java:72)
com.liferay.portal.kernel.servlet.filters.invoker.InvokerFilterChain.doFilter(InvokerFilterChain.java:116)
sun.reflect.GeneratedMethodAccessor382.invoke(Unknown Source)
sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
java.lang.reflect.Method.invoke(Method.java:597)
com.liferay.portal.kernel.bean.ClassLoaderBeanHandler.invoke(ClassLoaderBeanHandler.java:54)
$Proxy397.doFilter(Unknown Source)

~Mike
thumbnail
11年前 に Amit Doshi によって更新されました。

RE: Passing actionRequest params using actionResponse.sendRedirect

Liferay Master 投稿: 550 参加年月日: 10/12/29 最新の投稿
Hi,

I tried the below code and it is working fine in jsp page.

&lt;% ChargeTotal chargeTotal=(ChargeTotal) renderRequest.getPortletSession().getAttribute("chargeTotal");
if(chargeTotal != null)
{
	System.out.println(chargeTotal.getChargeTotal());
}

%&gt;


Please check and let me know.

Thanks & Regards,
Amit Doshi
thumbnail
11年前 に Michael Bravo によって更新されました。

RE: Passing actionRequest params using actionResponse.sendRedirect

New Member 投稿: 20 参加年月日: 12/04/26 最新の投稿
Amit,

Thanks again .. Unfortunately, I am still getting an error. It looks that after i do a redirect via:

actionRequest.getPortletSession().setAttribute("chargeTotal", chargeTotal);

actionResponse.sendRedirect(actionRequest.getContextPath()+redirectJSP);

.. I get a null pointer on the renderRequest object. Somehow I am losing the params when i do a straight actionResponse.sendRedirect.

When I use the actionResponse.setRenderParameter("jspPage","/thejsppage.jsp") .. i get the parameters. theissue with this is that the url is a dynamic url that we can't use when calling the payment vendor we are using. that's why i am trying to just redirect to the static jsp.

i'm wondering if there is a way to access the HttpServletRequest objects and set these .. I'm thinking that might help, but not sure ..

Again, thanks for the help. I am still pluggin away to find a solution! =)

Regards,
~Mike
thumbnail
11年前 に Amit Doshi によって更新されました。

RE: Passing actionRequest params using actionResponse.sendRedirect

Liferay Master 投稿: 550 参加年月日: 10/12/29 最新の投稿
Please use below code. It will help you to redirect to the Static page as you are aspecting.

For resonse.sendRedirect you should make one url by following code..

Code ::

String portletName = (String)actionRequest.getAttribute(WebKeys.PORTLET_ID);

ThemeDisplay themeDisplay = (ThemeDisplay) actionRequest.getAttribute(WebKeys.THEME_DISPLAY);

PortletURL redirectURL = PortletURLFactoryUtil.create(PortalUtil.getHttpServletRequest(actionRequest),
portletName,
themeDisplay.getLayout().getPlid(), PortletRequest.RENDER_PHASE);

redirectURL.setParameter("jspPage", "your jsp path");

actionResponse.sendRedirect(redirectURL.toString()); 


Hope it helps.

Thanks & Regards,
Amit Doshi
thumbnail
11年前 に Michael Bravo によって更新されました。

RE: Passing actionRequest params using actionResponse.sendRedirect

New Member 投稿: 20 参加年月日: 12/04/26 最新の投稿
Thanks Amit. I will give it a shot .. I appreciate all the help! ~Mike
thumbnail
11年前 に Michael Bravo によって更新されました。

RE: Passing actionRequest params using actionResponse.sendRedirect

New Member 投稿: 20 参加年月日: 12/04/26 最新の投稿
Amit ..

Awesome! That did it!! You're the man .. Thanks a million!.. emoticon
9年前 に Abdulbasit Shaikh によって更新されました。

RE: Passing actionRequest params using actionResponse.sendRedirect

New Member 投稿: 18 参加年月日: 13/05/16 最新の投稿
Thanks Amit. It really worked.

Thanks and Regards,
Abdulbasit F Shaikh.