Expand my Community achievements bar.

SOLVED

Access session storage in Java

Avatar

Level 2

Hi All,

I have items in session storage that I want to use in backend.

I have tried Servlet class with get method but was unable to get the item. 

Can anybody with experience help me out ?

1 Accepted Solution

Avatar

Correct answer by
Community Advisor

https://sling.apache.org/apidocs/sling11/org/apache/sling/api/SlingHttpServletRequest.html#getCookie... 

 

Here is the example

 

Cookie countryCookie = slingRequest.getCookie("myCountryCookie");
if(countryCookie==null) {
  String cookieValue = countryCookie.getValue();
// rest of the logic
}

 

https://github.com/arunpatidar02/aem63app-repo/blob/master/java/DemoCookieFilter.java 



Arun Patidar

View solution in original post

4 Replies

Avatar

Community Advisor

You cannot access browser session storage at server side, only cookies can be retrieve and updated from backed.



Arun Patidar

Avatar

Level 2

.

Avatar

Correct answer by
Community Advisor

https://sling.apache.org/apidocs/sling11/org/apache/sling/api/SlingHttpServletRequest.html#getCookie... 

 

Here is the example

 

Cookie countryCookie = slingRequest.getCookie("myCountryCookie");
if(countryCookie==null) {
  String cookieValue = countryCookie.getValue();
// rest of the logic
}

 

https://github.com/arunpatidar02/aem63app-repo/blob/master/java/DemoCookieFilter.java 



Arun Patidar

Avatar

Community Advisor

Once you get the cookie, map all the countries codes which you want to convert or maintain a Generic list in the AEM with all the mappings and get the values from the list

Please find the reference for using generic lists

https://adobe-consulting-services.github.io/acs-aem-commons/features/generic-lists/index.html

 

Hope this is helpful