provide-free-support Ujjwal's Blog: Liferay Session Sharing

Thursday, December 27, 2012

Liferay Session Sharing

Hi,


I had a requirement for sharing session information from Liferay Portal to Servlet deployed in same Liferay server. so, i developed Liferay portlet which callsPortalSession setParameter method and i store a string value to it. In my servlet, i use request.getSession().getParameter("NAME").

But, unfortunately, i got null value there. (Please note that servlet was a plain servlet and does not contain any liferay code in that war). After doing some reserarching, i found below evidence to achive this ::







STEP 1.

For Portlets who will share (i.e setAttribute() ) session attributes(s) need to add following entry in liferay-portlet.xml

<portlet>
<private-session-attributes>false</private-session-attributes>
</portlet>

STEP 2.

By default “LIFERAY_SHARED_”  prefix is used for sharing session attribute to other WARs.  It can be customized with in portal.properties ‘s session.shared.attributes value.

portletSession.setAttribute( "LIFERAY_SHARED_myVar",value,PortletSession.APPLICATION_SCOPE);

Other portlet(s)  in different WAR  can access it as below :

portletSession.getAttribute( "LIFERAY_SHARED_myVar",PortletSession.APPLICATION_SCOPE);


by implementing above code, i was able to get value stored in one portlet in other portlet which are deployed in different war files.

Now, i added a servlet in portlet where i was getting value from session.

I added below entry in liferay-portlet.xml

<portlet>
<private-session-attributes>true</private-session-attributes>
</portlet>

and i added below code in my portlet

Object value=portletSession.getAttribute( "LIFERAY_SHARED_myVar",PortletSession.APPLICATION_SCOPE);

 request.getSession().setAttribute("NAME", value);

Now, in my servlet, i was able to get value of NAME session attribute as below ::

Object valueFromSession=request.getSession().getAttribute("NAME");

For knowing more on Private Session xml attribute, refer my next blog post.

Cheers,

Ujjwal Soni

No comments:

best-it-exam-    | for-our-work-    | hottst-on-sale-    | it-sale-    | tast-dumps-us-    | test-king-number-    | pass-do-it-    | just-do-it-    | pass-with-us-    | passresults-everything-    | passtutor-our-dumps-    | realtests-us-exam-    | latest-update-source-for-    | cbtnuggets-sale-exam    | experts-revised-exam    | certguide-sale-exam    | test4-sale-exam    | get-well-prepared-    | certkiller-sale-exam    | buy-discount-dumps    | how-to-get-prepared-for-the    | in-an-easy-way    | brain-dumps-sale    | with-pass-exam-guarantee    | accurate-study-material    | at-first-try    | 100%-successful-rate    | get-certification-easily    | material-provider-exam    | real-exam-practice    | with-pass-score-guarantee    | certification-material-provider    | for-certification-professionals    | get-your-certification-successfully    | 100%-Pass-Rate    | in-pdf-file    | practice-exam-for    | it-study-guides    | study-material-sku    | study-guide-pdf    | prep-guide-demo    | certification-material-id    | actual-tests-demo    | brain-demos-test    | best-pdf-download    | our-certification-material    | best-practice-test    | leading-provider-on    | this-course-is-about    | the-most-reliable    | high-pass-rate-of    | high-pass-rate-demo    | recenty-updated-key    | only-for-students-free-download    | courseware-plus-kit-for    | accurate-answers-of    | the-most-reliable-id    | provide-training-for    | welcome-to-buy    | material-for-success-pass    | provide-free-support    | best-book-for-pass    | accuracy-of-the-answers    | pass-guarantee-id    | pass-exam-key    | pass-sku-id    | study-for-exid    | pdf-sku-exid    | sku-pdf-id    | pdf-demo-key    | exam-demo-ske    | pass-it-dump    |
http://www.menuiserie-dauvergne.com/    | http://www.menuiserie-dauvergne.com/    |